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;
47 tgt_count = desc->ld_tgt_count;
50 push_ctxt(&saved, &mds->mds_ctxt, NULL);
51 f = filp_open("LOVDESC", O_CREAT|O_RDWR, 0644);
53 CERROR("Cannot open/create LOVDESC file\n");
54 GOTO(out, rc = PTR_ERR(f));
57 rc = lustre_fwrite(f, (char *)desc, sizeof(*desc), &f->f_pos);
59 CERROR("Error closing LOVDESC file\n");
60 if (rc != sizeof(*desc)) {
61 CERROR("Cannot open/create LOVDESC file\n");
62 GOTO(out, rc = PTR_ERR(f));
65 f = filp_open("LOVTGTS", O_CREAT|O_RDWR, 0644);
67 CERROR("Cannot open/create LOVTGTS file\n");
68 GOTO(out, rc = PTR_ERR(f));
72 for (i = 0; i < tgt_count ; i++) {
73 rc = lustre_fwrite(f, uuidarray[i],
74 sizeof(uuidarray[i]), &f->f_pos);
75 if (rc != sizeof(uuidarray[i])) {
76 CERROR("cannot write LOV UUID %s (%d)\n",
85 CERROR("Error closing LOVTGTS file\n");
92 int mds_get_lovdesc(struct mds_obd *mds, struct lov_desc *desc)
94 struct obd_run_ctxt saved;
98 push_ctxt(&saved, &mds->mds_ctxt, NULL);
99 f = filp_open("LOVDESC", O_RDONLY, 0644);
100 if (!f || IS_ERR(f)) {
101 CERROR("Cannot open LOVDESC file\n");
106 rc = lustre_fread(f, (char *)desc, sizeof(*desc), &f->f_pos);
107 if (filp_close(f, 0))
108 CERROR("Error closing LOVDESC file\n");
110 if (rc != sizeof(*desc)) {
111 CERROR("Cannot read LOVDESC file\n");
120 int mds_get_lovtgts(struct mds_obd *mds, int tgt_count,obd_uuid_t *uuidarray)
122 struct obd_run_ctxt saved;
127 push_ctxt(&saved, &mds->mds_ctxt, NULL);
128 f = filp_open("LOVTGTS", O_RDONLY, 0644);
130 CERROR("Cannot open LOVTGTS file\n");
131 GOTO(out, rc = PTR_ERR(f));
134 rc = lustre_fread(f, (char *)uuidarray, tgt_count * sizeof(*uuidarray),
136 rc2 = filp_close(f, 0);
138 CERROR("Error closing LOVTGTS file: rc = %d\n", rc2);
140 if (rc != tgt_count * sizeof(*uuidarray)) {
141 CERROR("Error reading LOVTGTS file: rc = %d\n", rc);
154 int mds_iocontrol(long cmd, struct lustre_handle *conn,
155 int len, void *karg, void *uarg)
157 struct obd_device *obd = class_conn2obd(conn);
158 struct obd_ioctl_data *data = karg;
159 struct lov_desc *desc;
160 obd_uuid_t *uuidarray;
166 case OBD_IOC_LOV_SET_CONFIG:
167 desc = (struct lov_desc *)data->ioc_inlbuf1;
168 if (sizeof(*desc) > data->ioc_inllen1) {
169 CERROR("descriptor size wrong\n");
173 count = desc->ld_tgt_count;
174 uuidarray = (obd_uuid_t *)data->ioc_inlbuf2;
175 if (sizeof(*uuidarray) * count != data->ioc_inllen2) {
176 CERROR("UUID array size wrong\n");
179 rc = mds_set_lovdesc(obd, desc, uuidarray);
182 case OBD_IOC_LOV_GET_CONFIG:
183 desc = (struct lov_desc *)data->ioc_inlbuf1;
184 if (sizeof(*desc) > data->ioc_inllen1) {
185 CERROR("descriptor size wrong\n");
189 count = desc->ld_tgt_count;
190 uuidarray = (obd_uuid_t *)data->ioc_inlbuf2;
191 if (sizeof(*uuidarray) * count != data->ioc_inllen2) {
192 CERROR("UUID array size wrong\n");
195 rc = mds_get_lovdesc(&obd->u.mds, desc);
196 if (desc->ld_tgt_count > count) {
197 CERROR("UUID array size too small\n");
200 rc = mds_get_lovtgts(&obd->u.mds, desc->ld_tgt_count, uuidarray);