3 * OBDFS Super operations
5 * This code is issued under the GNU General Public License.
6 * See the file COPYING in this distribution
8 * Copryright (C) 1996 Peter J. Braam <braam@stelias.com>
9 * Copryright (C) 1999 Stelias Computing Inc. <braam@stelias.com>
10 * Copryright (C) 1999 Seagate Technology Inc.
11 * Copryright (C) 2001 Mountain View Data, Inc.
12 * Copryright (C) 2002 Cluster File Systems, Inc.
16 #include <linux/config.h>
17 #include <linux/module.h>
18 #include <linux/kernel.h>
20 #include <linux/string.h>
21 #include <linux/stat.h>
22 #include <linux/errno.h>
23 #include <linux/locks.h>
24 #include <linux/unistd.h>
26 #include <asm/system.h>
27 #include <asm/uaccess.h>
30 #include <linux/stat.h>
31 #include <asm/uaccess.h>
32 #include <linux/vmalloc.h>
33 #include <asm/segment.h>
35 #include <linux/obd_support.h>
36 #include <linux/obd_class.h>
37 #include <linux/lustre_light.h>
39 struct list_head ll_super_list;
40 extern struct address_space_operations ll_aops;
41 struct super_operations ll_super_operations;
42 long ll_cache_count = 0;
43 long ll_mutex_start = 0;
46 static char *ll_read_opt(const char *opt, char *data)
51 CDEBUG(D_INFO, "option: %s, data %s\n", opt, data);
52 if ( strncmp(opt, data, strlen(opt)) )
55 if ( (value = strchr(data, '=')) == NULL )
59 OBD_ALLOC(retval, char *, strlen(value) + 1);
61 printk(KERN_ALERT __FUNCTION__ ": out of memory!\n");
65 memcpy(retval, value, strlen(value)+1);
66 CDEBUG(D_PSDEV, "Assigned option: %s, value %s\n", opt, retval);
70 static void ll_options(char *options, char **dev, char **vers)
77 for (this_char = strtok (options, ",");
79 this_char = strtok (NULL, ",")) {
80 CDEBUG(D_INFO, "this_char %s\n", this_char);
81 if ( (!*dev && (*dev = ll_read_opt("device", this_char)))||
82 (!*vers && (*vers = ll_read_opt("version", this_char))) )
88 static struct super_block * ll_read_super(struct super_block *sb,
89 void *data, int silent)
91 struct inode *root = 0;
92 struct ll_sb_info *sbi = (struct ll_sb_info *)(&sb->u.generic_sbp);
93 struct obd_device *obddev;
105 memset(sbi, 0, sizeof(*sbi));
107 CDEBUG(D_INFO, "\n");
108 ll_options(data, &device, &version);
110 printk(__FUNCTION__ ": no device\n");
115 devno = simple_strtoul(device, NULL, 0);
116 CDEBUG(D_INFO, "\n");
117 if ( devno >= MAX_OBD_DEVICES ) {
118 printk(__FUNCTION__ ": device of %s too high (%d)\n", device, devno);
123 CDEBUG(D_INFO, "\n");
124 obddev = &obd_dev[devno];
127 CDEBUG(D_INFO, "\n");
128 if ( ! (obddev->obd_flags & OBD_ATTACHED) ||
129 ! (obddev->obd_flags & OBD_SET_UP) ){
130 printk("device %s not attached or not set up (%d)\n",
131 device, MINOR(devno));
136 CDEBUG(D_INFO, "\n");
137 sbi->ll_obd = obddev;
138 sbi->ll_ops = sbi->ll_obd->obd_type->typ_ops;
140 sbi->ll_conn.oc_dev = obddev;
141 err = sbi->ll_ops->o_connect(&sbi->ll_conn);
143 printk("OBDFS: cannot connect to %s\n", device);
149 CDEBUG(D_INFO, "\n");
150 /* list of dirty inodes, and a mutex to hold while modifying it */
151 INIT_LIST_HEAD(&sbi->ll_inodes);
152 init_MUTEX (&sbi->ll_list_mutex);
154 CDEBUG(D_INFO, "\n");
158 CDEBUG(D_INFO, "\n");
159 sb->s_maxbytes = 1LL << 36;
160 printk("Max bytes: %Lx\n", sb->s_maxbytes);
161 sb->s_blocksize = PAGE_SIZE;
162 sb->s_blocksize_bits = (unsigned char)PAGE_SHIFT;
163 sb->s_magic = LL_SUPER_MAGIC;
164 sb->s_op = &ll_super_operations;
166 /* make root inode */
167 CDEBUG(D_INFO, "\n");
168 oa = obdo_fromid(&sbi->ll_conn, root_ino, S_IFDIR,
169 OBD_MD_FLNOTOBD | OBD_MD_FLBLOCKS);
170 CDEBUG(D_INFO, "mode %o\n", oa->o_mode);
172 printk(__FUNCTION__ ": obdo_fromid failed\n");
177 CDEBUG(D_INFO, "\n");
178 root = iget4(sb, root_ino, NULL, oa);
180 CDEBUG(D_INFO, "\n");
182 printk("OBDFS: bad iget4 for root\n");
189 sb->s_root = d_alloc_root(root);
190 list_add(&sbi->ll_list, &ll_super_list);
191 OBD_FREE(device, strlen(device) + 1);
193 OBD_FREE(version, strlen(version) + 1);
200 OBD_FREE(device, strlen(device) + 1);
202 OBD_FREE(version, strlen(version) + 1);
204 sbi->ll_ops->o_disconnect(&sbi->ll_conn);
207 sbi->ll_super = NULL;
214 } /* ll_read_super */
217 static void ll_put_super(struct super_block *sb)
219 struct ll_sb_info *sbi;
224 sbi = (struct ll_sb_info *) &sb->u.generic_sbp;
225 //ll_flush_reqs(&sbi->ll_inodes, ~0UL);
227 OPS(sb,disconnect)(ID(sb));
228 list_del(&sbi->ll_list);
230 printk(KERN_INFO "OBDFS: Bye bye.\n");
237 void ll_do_change_inode(struct inode *inode, int valid)
243 if (IOPS(inode, setattr) == NULL) {
244 printk(KERN_ERR __FUNCTION__ ": no setattr method!\n");
250 printk(__FUNCTION__ ": obdo_alloc failed\n");
255 oa->o_valid = OBD_MD_FLNOTOBD & (valid | OBD_MD_FLID);
256 ll_from_inode(oa, inode);
257 oa->o_mode = inode->i_mode;
258 err = IOPS(inode, setattr)(IID(inode), oa);
261 printk(__FUNCTION__ ": obd_setattr fails (%d)\n", err);
265 } /* ll_write_inode */
267 void ll_change_inode(struct inode *inode, int mask)
269 return ll_do_change_inode(inode, OBD_MD_FLNLINK);
273 extern void write_inode_pages(struct inode *);
274 /* This routine is called from iput() (for each unlink on the inode).
275 * We can't put this call into delete_inode() since that is called only
276 * when i_count == 0, and we need to keep a reference on the inode while
277 * it is in the page cache, which means i_count > 0. Catch 22.
279 static void ll_put_inode(struct inode *inode)
282 if (inode->i_nlink && (atomic_read(&inode->i_count) == 1)) {
283 write_inode_pages(inode);
288 //ll_dequeue_pages(inode);
293 static void ll_delete_inode(struct inode *inode)
295 ll_do_change_inode(inode, ~0);
304 if (IOPS(inode, destroy) == NULL) {
305 printk(KERN_ERR __FUNCTION__ ": no destroy method!\n");
312 printk(__FUNCTION__ ": obdo_alloc failed\n");
316 oa->o_valid = OBD_MD_FLNOTOBD;
317 ll_from_inode(oa, inode);
319 /* XXX how do we know that this inode is now clean? */
320 printk("delete_inode ------> link %d\n", inode->i_nlink);
322 err = IOPS(inode, destroy)(IID(inode), oa);
326 printk(__FUNCTION__ ": obd_destroy fails (%d)\n", err);
332 } /* ll_delete_inode */
336 static int ll_attr2inode(struct inode * inode, struct iattr * attr)
338 unsigned int ia_valid = attr->ia_valid;
341 if (ia_valid & ATTR_SIZE) {
342 error = vmtruncate(inode, attr->ia_size);
347 if (ia_valid & ATTR_UID)
348 inode->i_uid = attr->ia_uid;
349 if (ia_valid & ATTR_GID)
350 inode->i_gid = attr->ia_gid;
351 if (ia_valid & ATTR_ATIME)
352 inode->i_atime = attr->ia_atime;
353 if (ia_valid & ATTR_MTIME)
354 inode->i_mtime = attr->ia_mtime;
355 if (ia_valid & ATTR_CTIME)
356 inode->i_ctime = attr->ia_ctime;
357 if (ia_valid & ATTR_MODE) {
358 inode->i_mode = attr->ia_mode;
359 if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID))
360 inode->i_mode &= ~S_ISGID;
366 int ll_setattr(struct dentry *de, struct iattr *attr)
368 struct inode *inode = de->d_inode;
373 if (IOPS(inode, setattr) == NULL) {
374 printk(KERN_ERR __FUNCTION__ ": no setattr method!\n");
380 printk(__FUNCTION__ ": obdo_alloc failed\n");
384 ll_attr2inode(inode, attr);
385 oa->o_id = inode->i_ino;
386 oa->o_mode = inode->i_mode;
387 obdo_from_iattr(oa, attr);
388 err = IOPS(inode, setattr)(IID(inode), oa);
391 printk(__FUNCTION__ ": obd_setattr fails (%d)\n", err);
400 static int ll_statfs(struct super_block *sb, struct statfs *buf)
407 err = OPS(sb,statfs)(ID(sb), &tmp);
409 printk(__FUNCTION__ ": obd_statfs fails (%d)\n", err);
412 memcpy(buf, &tmp, sizeof(*buf));
413 CDEBUG(D_SUPER, "statfs returns avail %ld\n", tmp.f_bavail);
419 static inline void ll_read_inode2(struct inode *inode, void *opaque)
421 struct obdo *oa = opaque;
424 ll_to_inode(inode, oa);
426 INIT_LIST_HEAD(ll_iplist(inode)); /* list of dirty pages on inode */
427 INIT_LIST_HEAD(ll_islist(inode)); /* list of inodes in superblock */
429 /* OIDEBUG(inode); */
431 if (S_ISREG(inode->i_mode)) {
432 inode->i_op = &ll_file_inode_operations;
433 inode->i_fop = &ll_file_operations;
434 inode->i_mapping->a_ops = &ll_aops;
436 } else if (S_ISDIR(inode->i_mode)) {
437 inode->i_op = &ll_dir_inode_operations;
438 inode->i_fop = &ll_dir_operations;
439 inode->i_mapping->a_ops = &ll_aops;
441 } else if (S_ISLNK(inode->i_mode)) {
442 if (inode->i_blocks) {
443 inode->i_op = &ll_symlink_inode_operations;
444 inode->i_mapping->a_ops = &ll_aops;
446 inode->i_op = &ll_fast_symlink_inode_operations;
450 init_special_inode(inode, inode->i_mode,
451 ((int *)ll_i2info(inode)->oi_inline)[0]);
458 /* exported operations */
459 struct super_operations ll_super_operations =
461 read_inode2: ll_read_inode2,
462 // put_inode: ll_put_inode,
463 // delete_inode: ll_delete_inode,
464 // put_super: ll_put_super,
470 struct file_system_type lustre_light_fs_type = {
471 "lustre_light", 0, ll_read_super, NULL
474 static int __init init_lustre_light(void)
476 printk(KERN_INFO "Lustre Light 0.0.1, braam@clusterfs.com\n");
478 return register_filesystem(&lustre_light_fs_type);
481 static void __exit exit_lustre_light(void)
483 unregister_filesystem(&lustre_light_fs_type);
486 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
487 MODULE_DESCRIPTION("Lustre Light Client File System v1.0");
488 MODULE_LICENSE("GPL");
490 module_init(init_lustre_light);
491 module_exit(exit_lustre_light);