1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * Lustre Metadata Server (mds) handling of striped file data
8 * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
10 * This code is issued under the GNU General Public License.
11 * See the file COPYING in this distribution
13 * by Peter Braam <braam@clusterfs.com> &
18 #define DEBUG_SUBSYSTEM S_MDS
20 #include <linux/module.h>
21 #include <linux/lustre_mds.h>
22 #include <linux/lustre_idl.h>
23 #include <linux/obd_class.h>
24 #include <linux/obd_lov.h>
25 #include <linux/lustre_lib.h>
27 /* lov_unpackdesc() is in lov/lov_pack.c */
29 void lov_packdesc(struct lov_desc *ld)
31 ld->ld_tgt_count = HTON__u32(ld->ld_tgt_count);
32 ld->ld_default_stripe_count = HTON__u32(ld->ld_default_stripe_count);
33 ld->ld_default_stripe_size = HTON__u32(ld->ld_default_stripe_size);
34 ld->ld_pattern = HTON__u32(ld->ld_pattern);
37 int mds_set_lovdesc(struct obd_device *obd, struct lov_desc *desc,
38 obd_uuid_t *uuidarray)
40 struct mds_obd *mds = &obd->u.mds;
41 struct obd_run_ctxt saved;
48 tgt_count = desc->ld_tgt_count;
51 push_ctxt(&saved, &mds->mds_ctxt, NULL);
52 f = filp_open("LOVDESC", O_CREAT|O_RDWR, 0644);
54 CERROR("Cannot open/create LOVDESC file\n");
55 GOTO(out, rc = PTR_ERR(f));
58 rc = lustre_fwrite(f, (char *)desc, sizeof(*desc), &f->f_pos);
60 CERROR("Error closing LOVDESC file\n");
61 if (rc != sizeof(*desc)) {
62 CERROR("Cannot open/create LOVDESC file\n");
63 GOTO(out, rc = PTR_ERR(f));
66 f = filp_open("LOVTGTS", O_CREAT|O_RDWR, 0644);
68 CERROR("Cannot open/create LOVTGTS file\n");
69 GOTO(out, rc = PTR_ERR(f));
73 for (i = 0; i < tgt_count ; i++) {
74 rc = lustre_fwrite(f, uuidarray[i],
75 sizeof(uuidarray[i]), &f->f_pos);
76 if (rc != sizeof(uuidarray[i])) {
77 CERROR("cannot write LOV UUID %s (%d)\n",
86 CERROR("Error closing LOVTGTS file\n");
89 pop_ctxt(&saved, &mds->mds_ctxt, NULL);
93 int mds_get_lovdesc(struct mds_obd *mds, struct lov_desc *desc)
95 struct obd_run_ctxt saved;
100 push_ctxt(&saved, &mds->mds_ctxt, NULL);
101 f = filp_open("LOVDESC", O_RDONLY, 0644);
103 CERROR("Cannot open LOVDESC file\n");
104 GOTO(out, rc = PTR_ERR(f));
107 rc = lustre_fread(f, (char *)desc, sizeof(*desc), &f->f_pos);
108 if (filp_close(f, 0))
109 CERROR("Error closing LOVDESC file\n");
111 if (rc != sizeof(*desc)) {
112 CERROR("Cannot read LOVDESC file: rc = %d\n", rc);
113 GOTO(out, rc = -EIO);
118 pop_ctxt(&saved, &mds->mds_ctxt, NULL);
123 int mds_get_lovtgts(struct mds_obd *mds, int tgt_count,obd_uuid_t *uuidarray)
125 struct obd_run_ctxt saved;
130 push_ctxt(&saved, &mds->mds_ctxt, NULL);
131 f = filp_open("LOVTGTS", O_RDONLY, 0644);
133 CERROR("Cannot open LOVTGTS file\n");
134 GOTO(out, rc = PTR_ERR(f));
137 rc = lustre_fread(f, (char *)uuidarray, tgt_count * sizeof(*uuidarray),
139 rc2 = filp_close(f, 0);
141 CERROR("Error closing LOVTGTS file: rc = %d\n", rc2);
143 if (rc != tgt_count * sizeof(*uuidarray)) {
144 CERROR("Error reading LOVTGTS file: rc = %d\n", rc);
152 pop_ctxt(&saved, &mds->mds_ctxt, NULL);
157 int mds_iocontrol(unsigned int cmd, struct lustre_handle *conn,
158 int len, void *karg, void *uarg)
160 struct obd_device *obd = class_conn2obd(conn);
161 struct obd_ioctl_data *data = karg;
162 struct lov_desc *desc;
163 obd_uuid_t *uuidarray;
169 case OBD_IOC_LOV_SET_CONFIG:
170 desc = (struct lov_desc *)data->ioc_inlbuf1;
171 if (sizeof(*desc) > data->ioc_inllen1) {
172 CERROR("descriptor size wrong\n");
176 count = desc->ld_tgt_count;
177 uuidarray = (obd_uuid_t *)data->ioc_inlbuf2;
178 if (sizeof(*uuidarray) * count != data->ioc_inllen2) {
179 CERROR("UUID array size wrong\n");
182 rc = mds_set_lovdesc(obd, desc, uuidarray);
185 case OBD_IOC_LOV_GET_CONFIG:
186 desc = (struct lov_desc *)data->ioc_inlbuf1;
187 if (sizeof(*desc) > data->ioc_inllen1) {
188 CERROR("descriptor size wrong\n");
192 count = desc->ld_tgt_count;
193 uuidarray = (obd_uuid_t *)data->ioc_inlbuf2;
194 if (sizeof(*uuidarray) * count != data->ioc_inllen2) {
195 CERROR("UUID array size wrong\n");
198 rc = mds_get_lovdesc(&obd->u.mds, desc);
199 if (desc->ld_tgt_count > count) {
200 CERROR("UUID array size too small\n");
203 rc = mds_get_lovtgts(&obd->u.mds, desc->ld_tgt_count, uuidarray);