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 int mds_set_lovdesc(struct obd_device *obd, struct lov_desc *desc,
28 obd_uuid_t *uuidarray)
30 struct mds_obd *mds = &obd->u.mds;
31 struct obd_run_ctxt saved;
37 tgt_count = desc->ld_tgt_count;
40 push_ctxt(&saved, &mds->mds_ctxt, NULL);
41 f = filp_open("LOVDESC", O_CREAT|O_RDWR, 0644);
43 CERROR("Cannot open/create LOVDESC file\n");
44 GOTO(out, rc = PTR_ERR(f));
47 rc = lustre_fwrite(f, (char *)desc, sizeof(*desc), &f->f_pos);
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));
55 f = filp_open("LOVTGTS", O_CREAT|O_RDWR, 0644);
57 CERROR("Cannot open/create LOVTGTS file\n");
58 GOTO(out, rc = PTR_ERR(f));
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",
75 CERROR("Error closing LOVTGTS file\n");
82 int mds_get_lovdesc(struct mds_obd *mds, struct lov_desc *desc)
84 struct obd_run_ctxt saved;
88 push_ctxt(&saved, &mds->mds_ctxt, NULL);
89 f = filp_open("LOVDESC", O_RDONLY, 0644);
90 if (!f || IS_ERR(f)) {
91 CERROR("Cannot open LOVDESC file\n");
96 rc = lustre_fread(f, (char *)desc, sizeof(*desc), &f->f_pos);
98 CERROR("Error closing LOVDESC file\n");
100 if (rc != sizeof(*desc)) {
101 CERROR("Cannot read LOVDESC file\n");
110 int mds_get_lovtgts(struct mds_obd *mds, int tgt_count,obd_uuid_t *uuidarray)
112 struct obd_run_ctxt saved;
117 push_ctxt(&saved, &mds->mds_ctxt, NULL);
118 f = filp_open("LOVTGTS", O_RDONLY, 0644);
120 CERROR("Cannot open LOVTGTS file\n");
121 GOTO(out, rc = PTR_ERR(f));
124 rc = lustre_fread(f, (char *)uuidarray, tgt_count * sizeof(*uuidarray),
126 rc2 = filp_close(f, 0);
128 CERROR("Error closing LOVTGTS file: rc = %d\n", rc2);
130 if (rc != tgt_count * sizeof(*uuidarray)) {
131 CERROR("Error reading LOVTGTS file: rc = %d\n", rc);
144 int mds_iocontrol(long cmd, struct lustre_handle *conn,
145 int len, void *karg, void *uarg)
147 struct obd_device *obd = class_conn2obd(conn);
148 struct obd_ioctl_data *data = karg;
149 struct lov_desc *desc;
150 obd_uuid_t *uuidarray;
156 case OBD_IOC_LOV_SET_CONFIG:
157 desc = (struct lov_desc *)data->ioc_inlbuf1;
158 if (sizeof(*desc) > data->ioc_inllen1) {
159 CERROR("descriptor size wrong\n");
163 count = desc->ld_tgt_count;
164 uuidarray = (obd_uuid_t *)data->ioc_inlbuf2;
165 if (sizeof(*uuidarray) * count != data->ioc_inllen2) {
166 CERROR("UUID array size wrong\n");
169 rc = mds_set_lovdesc(obd, desc, uuidarray);
172 case OBD_IOC_LOV_GET_CONFIG:
173 desc = (struct lov_desc *)data->ioc_inlbuf1;
174 if (sizeof(*desc) > data->ioc_inllen1) {
175 CERROR("descriptor size wrong\n");
179 count = desc->ld_tgt_count;
180 uuidarray = (obd_uuid_t *)data->ioc_inlbuf2;
181 if (sizeof(*uuidarray) * count != data->ioc_inllen2) {
182 CERROR("UUID array size wrong\n");
185 rc = mds_get_lovdesc(&obd->u.mds, desc);
186 if (desc->ld_tgt_count > count) {
187 CERROR("UUID array size too small\n");
190 rc = mds_get_lovtgts(&obd->u.mds, desc->ld_tgt_count, uuidarray);