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_configure_lov(struct obd_device *obd, struct lov_desc *desc,
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);
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 obd_device *obd, struct lov_desc *desc)
84 struct mds_obd *mds = &obd->u.mds;
85 struct obd_run_ctxt saved;
89 push_ctxt(&saved, &mds->mds_ctxt);
90 f = filp_open("LOVDESC", O_RDONLY, 0644);
91 if (!f || IS_ERR(f)) {
92 CERROR("Cannot open LOVDESC file\n");
97 rc = lustre_fread(f, (char *)desc, sizeof(*desc), &f->f_pos);
99 CERROR("Error closing LOVDESC file\n");
101 if (rc != sizeof(*desc)) {
102 CERROR("Cannot read LOVDESC file\n");
111 int mds_get_lovtgts(struct obd_device *obd, int tgt_count, uuid_t *uuidarray)
113 struct mds_obd *mds = &obd->u.mds;
114 struct obd_run_ctxt saved;
119 push_ctxt(&saved, &mds->mds_ctxt);
120 f = filp_open("LOVTGTS", O_RDONLY, 0644);
122 CERROR("Cannot open LOVTGTS file\n");
123 GOTO(out, rc = PTR_ERR(f));
126 rc = lustre_fread(f, (char *)uuidarray, tgt_count * sizeof(*uuidarray),
128 rc2 = filp_close(f, 0);
130 CERROR("Error closing LOVTGTS file: rc = %d\n", rc2);
132 if (rc != tgt_count * sizeof(*uuidarray)) {
133 CERROR("Error reading LOVTGTS file: rc = %d\n", rc);
146 int mds_iocontrol(long cmd, struct lustre_handle *conn,
147 int len, void *karg, void *uarg)
149 struct obd_device *obd = class_conn2obd(conn);
150 struct obd_ioctl_data *data = karg;
151 struct lov_desc *desc;
157 case OBD_IOC_LOV_CONFIG:
158 desc = (struct lov_desc *)data->ioc_inlbuf1;
159 if (sizeof(*desc) > data->ioc_inllen1) {
160 CERROR("descriptor size wrong\n");
164 count = desc->ld_tgt_count;
165 if (sizeof(uuid_t) * count != data->ioc_inllen2) {
166 CERROR("UUID array size wrong\n");
169 rc = mds_configure_lov(obd, desc, (uuid_t *)data->ioc_inlbuf2);