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_lov.h>
25 int mds_configure_lov(struct obd_device *obd, struct lov_desc *desc,
28 struct mds_obd *mds = &obd->u.mds;
29 struct obd_run_ctxt saved;
35 tgt_count = desc->ld_tgt_count;
38 push_ctxt(&saved, &mds->mds_ctxt);
39 f = filp_open("LOVDESC", O_CREAT|O_RDWR, 0644);
41 CERROR("Cannot open/create LOVDESC file\n");
42 GOTO(out, rc = PTR_ERR(f));
45 rc = lustre_fwrite(f, (char *)desc, sizeof(*desc), &f->f_pos);
47 CERROR("Error closing LOVDESC file\n");
48 if (rc != sizeof(*desc)) {
49 CERROR("Cannot open/create LOVDESC file\n");
50 GOTO(out, rc = PTR_ERR(f));
53 f = filp_open("LOVTGTS", O_CREAT|O_RDWR, 0644);
55 CERROR("Cannot open/create LOVTGTS file\n");
56 GOTO(out, rc = PTR_ERR(f));
60 for (i = 0; i < tgt_count ; i++) {
61 rc = lustre_fwrite(f, uuidarray[i],
62 sizeof(uuidarray[i]), &f->f_pos);
63 if (rc != sizeof(uuidarray[i])) {
64 CERROR("cannot write LOV UUID %s (%d)\n",
72 CERROR("Error closing LOVTGTS file\n");
79 int mds_get_lovdesc(struct obd_device *obd, struct lov_desc *desc)
81 struct mds_obd *mds = &obd->u.mds;
82 struct obd_run_ctxt saved;
86 push_ctxt(&saved, &mds->mds_ctxt);
87 f = filp_open("LOVDESC", O_RDONLY, 0644);
88 if (!f || IS_ERR(f)) {
89 CERROR("Cannot open LOVDESC file\n");
94 rc = lustre_fread(f, (char *)desc, sizeof(*desc), &f->f_pos);
96 CERROR("Error closing LOVDESC file\n");
98 if (rc != sizeof(*desc)) {
99 CERROR("Cannot read LOVDESC file\n");
108 int mds_get_lovtgts(struct obd_device *obd, int tgt_count, uuid_t *uuidarray)
110 struct mds_obd *mds = &obd->u.mds;
111 struct obd_run_ctxt saved;
116 push_ctxt(&saved, &mds->mds_ctxt);
117 f = filp_open("LOVTGTS", O_RDONLY, 0644);
119 CERROR("Cannot open LOVTGTS file\n");
120 GOTO(out, rc = PTR_ERR(f));
123 rc = lustre_fread(f, (char *)uuidarray, tgt_count * sizeof(uuid_t),
125 rc2 = filp_close(f, 0);
127 CERROR("Error closing LOVTGTS file: rc = %d\n", rc2);
129 if (rc != tgt_count * sizeof(uuid_t)) {
130 CERROR("Error reading LOVTGTS file: rc = %d\n", rc);
143 int mds_iocontrol(long cmd, struct lustre_handle *conn,
144 int len, void *karg, void *uarg)
146 struct obd_device *obd = class_conn2obd(conn);
147 struct obd_ioctl_data *data = karg;
148 struct lov_desc *desc;
154 case OBD_IOC_LOV_CONFIG:
155 desc = (struct lov_desc *)data->ioc_inlbuf1;
156 if (sizeof(*desc) > data->ioc_inllen1) {
157 CERROR("descriptor size wrong\n");
161 count = desc->ld_tgt_count;
162 if (sizeof(uuid_t) * count != data->ioc_inllen2) {
163 CERROR("UUID array size wrong\n");
166 rc = mds_configure_lov(obd, desc, (uuid_t *)data->ioc_inlbuf2);