Whamcloud - gitweb
* Change mds_client_info to mds_export_data and embed it in obd_export.
[fs/lustre-release.git] / lustre / mds / mds_lov.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  linux/mds/mds_lov.c
5  *
6  *  Lustre Metadata Server (mds) handling of striped file data
7  *
8  *  Copyright (C) 2001, 2002 Cluster File Systems, Inc.
9  *
10  *  This code is issued under the GNU General Public License.
11  *  See the file COPYING in this distribution
12  *
13  *  by Peter Braam <braam@clusterfs.com> &
14  *
15  */
16
17 #define EXPORT_SYMTAB
18 #define DEBUG_SUBSYSTEM S_MDS
19
20 #include <linux/module.h>
21 #include <linux/lustre_mds.h>
22 #include <linux/lustre_idl.h>
23 #include <linux/obd_lov.h>
24 #include <linux/obd_class.h>
25 #include <linux/lustre_lib.h>
26
27 int mds_configure_lov(struct obd_device *obd, struct lov_desc *desc,
28                       uuid_t *uuidarray)
29 {
30         struct mds_obd *mds = &obd->u.mds;
31         struct obd_run_ctxt saved;
32         struct file *f;
33         int tgt_count;
34         int rc;
35         int i;
36
37         tgt_count = desc->ld_tgt_count;
38         lov_packdesc(desc);
39
40         push_ctxt(&saved, &mds->mds_ctxt);
41         f = filp_open("LOVDESC", O_CREAT|O_RDWR, 0644);
42         if (IS_ERR(f)) {
43                 CERROR("Cannot open/create LOVDESC file\n");
44                 GOTO(out, rc = PTR_ERR(f));
45         }
46
47         rc = lustre_fwrite(f, (char *)desc, sizeof(*desc), &f->f_pos);
48         if (filp_close(f, 0))
49                 CERROR("Error closing LOVDESC file\n");
50         if (rc != sizeof(*desc)) {
51                 CERROR("Cannot open/create LOVDESC file\n");
52                 GOTO(out, rc = PTR_ERR(f));
53         }
54
55         f = filp_open("LOVTGTS", O_CREAT|O_RDWR, 0644);
56         if (IS_ERR(f)) {
57                 CERROR("Cannot open/create LOVTGTS file\n");
58                 GOTO(out, rc = PTR_ERR(f));
59         }
60
61         rc = 0;
62         for (i = 0; i < tgt_count ; i++) {
63                 rc = lustre_fwrite(f, uuidarray[i],
64                                    sizeof(uuidarray[i]), &f->f_pos);
65                 if (rc != sizeof(uuidarray[i])) {
66                         CERROR("cannot write LOV UUID %s (%d)\n",
67                                uuidarray[i], i);
68                         if (rc >= 0)
69                                 rc = -EIO;
70                         break;
71                 }
72         }
73         if (filp_close(f, 0))
74                 CERROR("Error closing LOVTGTS file\n");
75
76 out:
77         pop_ctxt(&saved);
78         RETURN(rc);
79 }
80
81 int mds_get_lovdesc(struct obd_device *obd, struct lov_desc *desc)
82 {
83         struct mds_obd *mds = &obd->u.mds;
84         struct obd_run_ctxt saved;
85         struct file *f;
86         int rc;
87
88         push_ctxt(&saved, &mds->mds_ctxt);
89         f = filp_open("LOVDESC", O_RDONLY, 0644);
90         if (!f || IS_ERR(f)) {
91                 CERROR("Cannot open LOVDESC file\n");
92                 pop_ctxt(&saved);
93                 RETURN(-EIO);
94         }
95
96         rc = lustre_fread(f, (char *)desc, sizeof(*desc), &f->f_pos);
97         if (filp_close(f, 0))
98                 CERROR("Error closing LOVDESC file\n");
99
100         if (rc != sizeof(*desc)) {
101                 CERROR("Cannot read LOVDESC file\n");
102                 pop_ctxt(&saved);
103                 RETURN(-EIO);
104         }
105         pop_ctxt(&saved);
106
107         RETURN(0);
108 }
109
110 int mds_get_lovtgts(struct obd_device *obd, int tgt_count, uuid_t *uuidarray)
111 {
112         struct mds_obd *mds = &obd->u.mds;
113         struct obd_run_ctxt saved;
114         struct file *f;
115         int rc;
116         int rc2;
117
118         push_ctxt(&saved, &mds->mds_ctxt);
119         f = filp_open("LOVTGTS", O_RDONLY, 0644);
120         if (IS_ERR(f)) {
121                 CERROR("Cannot open LOVTGTS file\n");
122                 GOTO(out, rc = PTR_ERR(f));
123         }
124
125         rc = lustre_fread(f, (char *)uuidarray, tgt_count * sizeof(uuid_t),
126                           &f->f_pos);
127         rc2 = filp_close(f, 0);
128         if (rc2)
129                 CERROR("Error closing LOVTGTS file: rc = %d\n", rc2);
130
131         if (rc != tgt_count * sizeof(uuid_t)) {
132                 CERROR("Error reading LOVTGTS file: rc = %d\n", rc);
133                 if (rc >= 0)
134                         rc = -EIO;
135                 GOTO(out, rc);
136         } else 
137                 rc = 0;
138         EXIT;
139 out:
140         pop_ctxt(&saved);
141
142         RETURN(rc);
143 }
144
145 int mds_iocontrol(long cmd, struct lustre_handle *conn,
146                           int len, void *karg, void *uarg)
147 {
148         struct obd_device *obd = class_conn2obd(conn);
149         struct obd_ioctl_data *data = karg;
150         struct lov_desc *desc;
151         int count;
152         int rc;
153
154
155         switch (cmd) {
156         case OBD_IOC_LOV_CONFIG:
157                 desc = (struct lov_desc *)data->ioc_inlbuf1;
158                 if (sizeof(*desc) > data->ioc_inllen1) {
159                         CERROR("descriptor size wrong\n");
160                         RETURN(-EINVAL);
161                 }
162
163                 count = desc->ld_tgt_count;
164                 if (sizeof(uuid_t) * count != data->ioc_inllen2) {
165                         CERROR("UUID array size wrong\n");
166                         RETURN(-EINVAL);
167                 }
168                 rc = mds_configure_lov(obd, desc, (uuid_t *)data->ioc_inlbuf2);
169
170                 RETURN(rc);
171         default:
172                 RETURN(-EINVAL);
173         }
174
175         RETURN(0);
176 }