1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Lustre Light Super operations
6 * This code is issued under the GNU General Public License.
7 * See the file COPYING in this distribution
9 * Copryright (C) 1996 Peter J. Braam <braam@stelias.com>
10 * Copryright (C) 1999 Stelias Computing Inc. <braam@stelias.com>
11 * Copryright (C) 1999 Seagate Technology Inc.
12 * Copryright (C) 2001 Mountain View Data, Inc.
13 * Copryright (C) 2002 Cluster File Systems, Inc.
17 #include <linux/config.h>
18 #include <linux/module.h>
19 #include <linux/kernel.h>
21 #include <linux/string.h>
22 #include <linux/stat.h>
23 #include <linux/errno.h>
24 #include <linux/locks.h>
25 #include <linux/unistd.h>
27 #include <asm/system.h>
28 #include <asm/uaccess.h>
31 #include <linux/stat.h>
32 #include <asm/uaccess.h>
33 #include <asm/segment.h>
35 #define DEBUG_SUBSYSTEM S_LLIGHT
37 #include <linux/lustre_light.h>
39 kmem_cache_t *ll_file_data_slab;
40 extern struct address_space_operations ll_aops;
41 extern struct address_space_operations ll_dir_aops;
42 struct super_operations ll_super_operations;
44 static char *ll_read_opt(const char *opt, char *data)
50 CDEBUG(D_INFO, "option: %s, data %s\n", opt, data);
51 if ( strncmp(opt, data, strlen(opt)) ) {
55 if ( (value = strchr(data, '=')) == NULL ) {
61 OBD_ALLOC(retval, strlen(value) + 1);
63 CERROR("out of memory!\n");
67 memcpy(retval, value, strlen(value)+1);
68 CDEBUG(D_SUPER, "Assigned option: %s, value %s\n", opt, retval);
73 static void ll_options(char *options, char **dev, char **vers)
83 for (this_char = strtok (options, ",");
85 this_char = strtok (NULL, ",")) {
86 CDEBUG(D_INFO, "this_char %s\n", this_char);
87 if ( (!*dev && (*dev = ll_read_opt("device", this_char)))||
88 (!*vers && (*vers = ll_read_opt("version", this_char))) )
94 static struct super_block * ll_read_super(struct super_block *sb,
95 void *data, int silent)
97 struct inode *root = 0;
98 struct ll_sb_info *sbi;
100 char *version = NULL;
103 struct ptlrpc_request *request = NULL;
108 OBD_ALLOC(sbi, sizeof(*sbi));
114 sb->u.generic_sbp = sbi;
116 ll_options(data, &device, &version);
119 CERROR("no device\n");
120 GOTO(out_free, sb = NULL);
123 devno = simple_strtoul(device, NULL, 0);
124 if ( devno >= MAX_OBD_DEVICES ) {
125 CERROR("device of %s too high\n", device);
126 GOTO(out_free, sb = NULL);
129 sbi->ll_conn.oc_dev = &obd_dev[devno];
130 err = obd_connect(&sbi->ll_conn);
132 CERROR("cannot connect to %s\n", device);
133 GOTO(out_free, sb = NULL);
136 /* the first parameter should become an mds device no */
137 err = ptlrpc_connect_client(-1, "mds",
138 MDS_REQUEST_PORTAL, MDC_REPLY_PORTAL,
139 &sbi->ll_mds_client);
142 CERROR("cannot find MDS\n");
143 GOTO(out_disc, sb = NULL);
148 sb->s_maxbytes = 1LL << 36;
149 sb->s_blocksize = PAGE_SIZE;
150 sb->s_blocksize_bits = (unsigned char)PAGE_SHIFT;
151 sb->s_magic = LL_SUPER_MAGIC;
152 sb->s_op = &ll_super_operations;
154 /* make root inode */
155 err = mdc_getattr(&sbi->ll_mds_client, sbi->ll_rootino, S_IFDIR,
156 OBD_MD_FLNOTOBD|OBD_MD_FLBLOCKS, &request);
158 CERROR("mdc_getattr failed for root %d\n", err);
159 GOTO(out_req, sb = NULL);
162 root = iget4(sb, sbi->ll_rootino, NULL,
163 lustre_msg_buf(request->rq_repmsg, 0));
165 sb->s_root = d_alloc_root(root);
167 CERROR("lustre_light: bad iget4 for root\n");
168 GOTO(out_req, sb = NULL);
172 ptlrpc_free_req(request);
175 obd_disconnect(&sbi->ll_conn);
178 OBD_FREE(sbi, sizeof(*sbi));
180 OBD_FREE(device, strlen(device) + 1);
181 OBD_FREE(version, strlen(version) + 1);
184 } /* ll_read_super */
186 static void ll_put_super(struct super_block *sb)
188 struct ll_sb_info *sbi = sb->u.generic_sbp;
190 obd_disconnect(&sbi->ll_conn);
191 OBD_FREE(sb->u.generic_sbp, sizeof(*sbi));
197 extern inline struct obdo * ll_oa_from_inode(struct inode *inode, int valid);
198 static void ll_delete_inode(struct inode *inode)
200 if (S_ISREG(inode->i_mode)) {
203 oa = ll_oa_from_inode(inode, OBD_MD_FLNOTOBD);
205 CERROR("no memory\n");
208 err = obd_destroy(ll_i2obdconn(inode), oa);
209 CDEBUG(D_INODE, "obd destroy of %Ld error %d\n",
217 /* like inode_setattr, but doesn't mark the inode dirty */
218 static int ll_attr2inode(struct inode * inode, struct iattr * attr, int trunc)
220 unsigned int ia_valid = attr->ia_valid;
223 if ((ia_valid & ATTR_SIZE) && trunc ) {
224 error = vmtruncate(inode, attr->ia_size);
227 } else if (ia_valid & ATTR_SIZE) {
228 inode->i_size = attr->ia_size;
231 if (ia_valid & ATTR_UID)
232 inode->i_uid = attr->ia_uid;
233 if (ia_valid & ATTR_GID)
234 inode->i_gid = attr->ia_gid;
235 if (ia_valid & ATTR_ATIME)
236 inode->i_atime = attr->ia_atime;
237 if (ia_valid & ATTR_MTIME)
238 inode->i_mtime = attr->ia_mtime;
239 if (ia_valid & ATTR_CTIME)
240 inode->i_ctime = attr->ia_ctime;
241 if (ia_valid & ATTR_MODE) {
242 inode->i_mode = attr->ia_mode;
243 if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID))
244 inode->i_mode &= ~S_ISGID;
250 int ll_inode_setattr(struct inode *inode, struct iattr *attr, int do_trunc)
252 struct ptlrpc_request *request;
253 struct ll_sb_info *sbi = ll_i2sbi(inode);
258 /* change incore inode */
259 ll_attr2inode(inode, attr, do_trunc);
261 err = mdc_setattr(&sbi->ll_mds_client, inode, attr, &request);
263 CERROR("mdc_setattr fails (%d)\n", err);
265 ptlrpc_free_req(request);
271 int ll_setattr(struct dentry *de, struct iattr *attr)
273 return ll_inode_setattr(de->d_inode, attr, 1);
276 static int ll_statfs(struct super_block *sb, struct statfs *buf)
283 err = obd_statfs(ID(sb), &tmp);
285 CERROR("obd_statfs fails (%d)\n", err);
288 memcpy(buf, &tmp, sizeof(*buf));
289 CDEBUG(D_SUPER, "statfs returns avail %ld\n", tmp.f_bavail);
295 static void inline ll_to_inode(struct inode *dst, struct mds_body *body)
297 struct ll_inode_info *ii =
298 (struct ll_inode_info *) &dst->u.generic_ip;
300 /* core attributes first */
301 if ( body->valid & OBD_MD_FLID )
302 dst->i_ino = body->ino;
303 if ( body->valid & OBD_MD_FLATIME )
304 dst->i_atime = body->atime;
305 if ( body->valid & OBD_MD_FLMTIME )
306 dst->i_mtime = body->mtime;
307 if ( body->valid & OBD_MD_FLCTIME )
308 dst->i_ctime = body->ctime;
309 if ( body->valid & OBD_MD_FLSIZE )
310 dst->i_size = body->size;
311 if ( body->valid & OBD_MD_FLMODE )
312 dst->i_mode = body->mode;
313 if ( body->valid & OBD_MD_FLUID )
314 dst->i_uid = body->uid;
315 if ( body->valid & OBD_MD_FLGID )
316 dst->i_gid = body->gid;
317 if ( body->valid & OBD_MD_FLFLAGS )
318 dst->i_flags = body->flags;
319 if ( body->valid & OBD_MD_FLNLINK )
320 dst->i_nlink = body->nlink;
321 if ( body->valid & OBD_MD_FLGENER )
322 dst->i_generation = body->generation;
324 /* this will become more elaborate for striping etc */
325 if (body->valid & OBD_MD_FLOBJID)
326 ii->lli_objid = body->objid;
329 if (obdo_has_inline(oa)) {
330 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) ||
331 S_ISFIFO(inode->i_mode)) {
332 obd_rdev rdev = *((obd_rdev *)oa->o_inline);
334 "copying device %x from obdo to inode\n", rdev);
335 init_special_inode(inode, inode->i_mode, rdev);
337 CDEBUG(D_INFO, "copying inline from obdo to inode\n");
338 memcpy(oinfo->lli_inline, oa->o_inline, OBD_INLINESZ);
340 oinfo->lli_flags |= OBD_FL_INLINEDATA;
345 static inline void ll_read_inode2(struct inode *inode, void *opaque)
347 struct mds_body *body = opaque;
350 ll_to_inode(inode, body);
352 /* OIDEBUG(inode); */
354 if (S_ISREG(inode->i_mode)) {
355 inode->i_op = &ll_file_inode_operations;
356 inode->i_fop = &ll_file_operations;
357 inode->i_mapping->a_ops = &ll_aops;
359 } else if (S_ISDIR(inode->i_mode)) {
360 inode->i_op = &ll_dir_inode_operations;
361 inode->i_fop = &ll_dir_operations;
362 inode->i_mapping->a_ops = &ll_dir_aops;
364 } else if (S_ISLNK(inode->i_mode)) {
365 inode->i_op = &ll_fast_symlink_inode_operations;
368 init_special_inode(inode, inode->i_mode,
369 ((int *)ll_i2info(inode)->lli_inline)[0]);
376 /* exported operations */
377 struct super_operations ll_super_operations =
379 read_inode2: ll_read_inode2,
380 delete_inode: ll_delete_inode,
381 put_super: ll_put_super,
385 struct file_system_type lustre_light_fs_type = {
386 "lustre_light", 0, ll_read_super, NULL
389 static int __init init_lustre_light(void)
391 printk(KERN_INFO "Lustre Light 0.0.1, braam@clusterfs.com\n");
392 ll_file_data_slab = kmem_cache_create("ll_file_data",
393 sizeof(struct ll_file_data), 0,
394 SLAB_HWCACHE_ALIGN, NULL, NULL);
395 if (ll_file_data_slab == NULL)
398 return register_filesystem(&lustre_light_fs_type);
401 static void __exit exit_lustre_light(void)
403 unregister_filesystem(&lustre_light_fs_type);
404 kmem_cache_destroy(ll_file_data_slab);
407 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
408 MODULE_DESCRIPTION("Lustre Light Client File System v1.0");
409 MODULE_LICENSE("GPL");
411 module_init(init_lustre_light);
412 module_exit(exit_lustre_light);