Whamcloud - gitweb
Add module refcounts for filesystem interface modules.
[fs/lustre-release.git] / lustre / mds / mds_lov.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  linux/mds/mds_lov.c
5  *
6  *  Lustre Metadata Server (mds) handling of striped file data
7  *
8  *  Copyright (C) 2001, 2002 Cluster File Systems, Inc.
9  *
10  *  This code is issued under the GNU General Public License.
11  *  See the file COPYING in this distribution
12  *
13  *  by Peter Braam <braam@clusterfs.com> &
14  *
15  */
16
17 #define EXPORT_SYMTAB
18 #define DEBUG_SUBSYSTEM S_MDS
19
20 #include <linux/module.h>
21 #include <linux/lustre_mds.h>
22 #include <linux/lustre_idl.h>
23 #include <linux/obd_lov.h>
24
25 int mds_configure_lov(struct obd_device *obd, struct lov_desc *desc,
26                       uuid_t *uuidarray)
27 {
28         struct mds_obd *mds = &obd->u.mds;
29         struct obd_run_ctxt saved;
30         struct file *f;
31         int tgt_count;
32         int rc;
33         int i;
34
35         tgt_count = desc->ld_tgt_count;
36         lov_packdesc(desc);
37
38         push_ctxt(&saved, &mds->mds_ctxt);
39         f = filp_open("LOVDESC", O_CREAT|O_RDWR, 0644);
40         if (IS_ERR(f)) {
41                 CERROR("Cannot open/create LOVDESC file\n");
42                 GOTO(out, rc = PTR_ERR(f));
43         }
44
45         rc = lustre_fwrite(f, (char *)desc, sizeof(*desc), &f->f_pos);
46         if (filp_close(f, 0))
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));
51         }
52
53         f = filp_open("LOVTGTS", O_CREAT|O_RDWR, 0644);
54         if (IS_ERR(f)) {
55                 CERROR("Cannot open/create LOVTGTS file\n");
56                 GOTO(out, rc = PTR_ERR(f));
57         }
58
59         rc = 0;
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",
65                                uuidarray[i], i);
66                         if (rc >= 0)
67                                 rc = -EIO;
68                         break;
69                 }
70         }
71         if (filp_close(f, 0))
72                 CERROR("Error closing LOVTGTS file\n");
73
74 out:
75         pop_ctxt(&saved);
76         RETURN(rc);
77 }
78
79 int mds_get_lovdesc(struct obd_device *obd, struct lov_desc *desc)
80 {
81         struct mds_obd *mds = &obd->u.mds;
82         struct obd_run_ctxt saved;
83         struct file *f;
84         int rc;
85
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");
90                 pop_ctxt(&saved);
91                 RETURN(-EIO);
92         }
93
94         rc = lustre_fread(f, (char *)desc, sizeof(*desc), &f->f_pos);
95         if (filp_close(f, 0))
96                 CERROR("Error closing LOVDESC file\n");
97
98         if (rc != sizeof(*desc)) {
99                 CERROR("Cannot read LOVDESC file\n");
100                 pop_ctxt(&saved);
101                 RETURN(-EIO);
102         }
103         pop_ctxt(&saved);
104
105         RETURN(0);
106 }
107
108 int mds_get_lovtgts(struct obd_device *obd, int tgt_count, uuid_t *uuidarray)
109 {
110         struct mds_obd *mds = &obd->u.mds;
111         struct obd_run_ctxt saved;
112         struct file *f;
113         int rc;
114         int rc2;
115         int count;
116
117         push_ctxt(&saved, &mds->mds_ctxt);
118         f = filp_open("LOVTGTS", O_RDONLY, 0644);
119         if (IS_ERR(f)) {
120                 CERROR("Cannot open LOVTGTS file\n");
121                 GOTO(out, rc = PTR_ERR(f));
122         }
123
124         rc = lustre_fread(f, (char *)uuidarray, tgt_count * sizeof(uuid_t),
125                           &f->f_pos);
126         rc2 = filp_close(f, 0);
127         if (rc2)
128                 CERROR("Error closing LOVTGTS file: rc = %d\n", rc2);
129
130         if (rc != count * sizeof(uuid_t)) {
131                 CERROR("Error reading LOVTGTS file: rc = %d\n", rc);
132                 if (rc >= 0)
133                         rc = -EIO;
134                 GOTO(out, rc);
135         }
136         EXIT;
137 out:
138         pop_ctxt(&saved);
139
140         RETURN(rc);
141 }
142
143 int mds_iocontrol(long cmd, struct lustre_handle *conn,
144                           int len, void *karg, void *uarg)
145 {
146         struct obd_device *obd = class_conn2obd(conn);
147         struct obd_ioctl_data *data = karg;
148         struct lov_desc *desc;
149         int count;
150         int rc;
151
152
153         switch (cmd) {
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");
158                         RETURN(-EINVAL);
159                 }
160
161                 count = desc->ld_tgt_count;
162                 if (sizeof(uuid_t) * count != data->ioc_inllen2) {
163                         CERROR("UUID array size wrong\n");
164                         RETURN(-EINVAL);
165                 }
166                 rc = mds_configure_lov(obd, desc, (uuid_t *)data->ioc_inlbuf2);
167
168                 RETURN(rc);
169         default:
170                 RETURN(-EINVAL);
171         }
172
173         RETURN(0);
174 }