2 * Lustre Light Super operations
4 * This code is issued under the GNU General Public License.
5 * See the file COPYING in this distribution
7 * Copryright (C) 1996 Peter J. Braam <braam@stelias.com>
8 * Copryright (C) 1999 Stelias Computing Inc. <braam@stelias.com>
9 * Copryright (C) 1999 Seagate Technology Inc.
10 * Copryright (C) 2001 Mountain View Data, Inc.
11 * Copryright (C) 2002 Cluster File Systems, Inc.
15 #include <linux/config.h>
16 #include <linux/module.h>
17 #include <linux/kernel.h>
19 #include <linux/string.h>
20 #include <linux/stat.h>
21 #include <linux/errno.h>
22 #include <linux/locks.h>
23 #include <linux/unistd.h>
25 #include <asm/system.h>
26 #include <asm/uaccess.h>
29 #include <linux/stat.h>
30 #include <asm/uaccess.h>
31 #include <linux/vmalloc.h>
32 #include <asm/segment.h>
34 #include <linux/obd_support.h>
35 #include <linux/obd_class.h>
36 #include <linux/lustre_light.h>
38 //struct list_head ll_super_list;
39 extern struct address_space_operations ll_aops;
40 extern struct address_space_operations ll_dir_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);
99 struct ptlrep_hdr *hdr = NULL;
104 memset(sbi, 0, sizeof(*sbi));
106 ll_options(data, &device, &version);
108 printk(__FUNCTION__ ": no device\n");
113 devno = simple_strtoul(device, NULL, 0);
114 if ( devno >= MAX_OBD_DEVICES ) {
115 printk(__FUNCTION__ ": device of %s too high\n", device);
120 sbi->ll_conn.oc_dev = &obd_dev[devno];
121 err = obd_connect(&sbi->ll_conn);
123 printk(__FUNCTION__ "cannot connect to %s\n", device);
132 sb->s_maxbytes = 1LL << 36;
133 sb->s_blocksize = PAGE_SIZE;
134 sb->s_blocksize_bits = (unsigned char)PAGE_SHIFT;
135 sb->s_magic = LL_SUPER_MAGIC;
136 sb->s_op = &ll_super_operations;
138 /* make root inode */
139 err = mdc_getattr(sbi->ll_rootino, S_IFDIR,
140 OBD_MD_FLNOTOBD|OBD_MD_FLBLOCKS,
143 printk(__FUNCTION__ ": mds_getattr failed for root %d\n", err);
148 root = iget4(sb, sbi->ll_rootino, NULL, rep);
150 sb->s_root = d_alloc_root(root);
152 printk("lustre_light: bad iget4 for root\n");
161 OBD_FREE(device, strlen(device) + 1);
163 OBD_FREE(version, strlen(version) + 1);
164 if (!sb && connected)
165 obd_disconnect(&sbi->ll_conn);
175 } /* ll_read_super */
177 static void ll_put_super(struct super_block *sb)
181 obd_disconnect(ID(sb));
188 extern void write_inode_pages(struct inode *);
189 /* This routine is called from iput() (for each unlink on the inode).
190 * We can't put this call into delete_inode() since that is called only
191 * when i_count == 0, and we need to keep a reference on the inode while
192 * it is in the page cache, which means i_count > 0. Catch 22.
194 static void ll_put_inode(struct inode *inode)
197 if (inode->i_nlink && (atomic_read(&inode->i_count) == 1)) {
198 write_inode_pages(inode);
203 //ll_dequeue_pages(inode);
207 /* like inode_setattr, but doesn't mark the inode dirty */
208 static int ll_attr2inode(struct inode * inode, struct iattr * attr)
210 unsigned int ia_valid = attr->ia_valid;
213 if (ia_valid & ATTR_SIZE) {
214 error = vmtruncate(inode, attr->ia_size);
218 if (ia_valid & ATTR_UID)
219 inode->i_uid = attr->ia_uid;
220 if (ia_valid & ATTR_GID)
221 inode->i_gid = attr->ia_gid;
222 if (ia_valid & ATTR_ATIME)
223 inode->i_atime = attr->ia_atime;
224 if (ia_valid & ATTR_MTIME)
225 inode->i_mtime = attr->ia_mtime;
226 if (ia_valid & ATTR_CTIME)
227 inode->i_ctime = attr->ia_ctime;
228 if (ia_valid & ATTR_MODE) {
229 inode->i_mode = attr->ia_mode;
230 if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID))
231 inode->i_mode &= ~S_ISGID;
237 int ll_setattr(struct dentry *de, struct iattr *attr)
239 struct inode *inode = de->d_inode;
240 struct ptlrep_hdr *hdr = NULL;
245 /* change incore inode */
246 ll_attr2inode(inode, attr);
248 err = mdc_setattr(inode, attr, NULL, &hdr);
250 printk(__FUNCTION__ ": ll_setattr fails (%d)\n", err);
258 static int ll_statfs(struct super_block *sb, struct statfs *buf)
265 err = obd_statfs(ID(sb), &tmp);
267 printk(__FUNCTION__ ": obd_statfs fails (%d)\n", err);
270 memcpy(buf, &tmp, sizeof(*buf));
271 CDEBUG(D_SUPER, "statfs returns avail %ld\n", tmp.f_bavail);
277 static void inline ll_to_inode(struct inode *dst, struct mds_rep *rep)
279 struct ll_inode_info *ii =
280 (struct ll_inode_info *) &dst->u.generic_ip;
282 /* core attributes first */
283 if ( rep->valid & OBD_MD_FLID )
284 dst->i_ino = rep->ino;
285 if ( rep->valid & OBD_MD_FLATIME )
286 dst->i_atime = rep->atime;
287 if ( rep->valid & OBD_MD_FLMTIME )
288 dst->i_mtime = rep->mtime;
289 if ( rep->valid & OBD_MD_FLCTIME )
290 dst->i_ctime = rep->ctime;
291 if ( rep->valid & OBD_MD_FLSIZE )
292 dst->i_size = rep->size;
293 if ( rep->valid & OBD_MD_FLMODE )
294 dst->i_mode = rep->mode;
295 if ( rep->valid & OBD_MD_FLUID )
296 dst->i_uid = rep->uid;
297 if ( rep->valid & OBD_MD_FLGID )
298 dst->i_gid = rep->gid;
299 if ( rep->valid & OBD_MD_FLFLAGS )
300 dst->i_flags = rep->flags;
301 if ( rep->valid & OBD_MD_FLNLINK )
302 dst->i_nlink = rep->nlink;
303 if ( rep->valid & OBD_MD_FLGENER )
304 dst->i_generation = rep->generation;
306 /* this will become more elaborate for striping etc */
307 if (rep->valid & OBD_MD_FLOBJID)
308 ii->lli_objid = rep->objid;
311 if (obdo_has_inline(oa)) {
312 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) ||
313 S_ISFIFO(inode->i_mode)) {
314 obd_rdev rdev = *((obd_rdev *)oa->o_inline);
316 "copying device %x from obdo to inode\n", rdev);
317 init_special_inode(inode, inode->i_mode, rdev);
319 CDEBUG(D_INFO, "copying inline from obdo to inode\n");
320 memcpy(oinfo->lli_inline, oa->o_inline, OBD_INLINESZ);
322 oinfo->lli_flags |= OBD_FL_INLINEDATA;
327 static inline void ll_read_inode2(struct inode *inode, void *opaque)
329 struct mds_rep *rep = opaque;
332 ll_to_inode(inode, rep);
334 /* OIDEBUG(inode); */
336 if (S_ISREG(inode->i_mode)) {
337 inode->i_op = &ll_file_inode_operations;
338 inode->i_fop = &ll_file_operations;
339 inode->i_mapping->a_ops = &ll_aops;
341 } else if (S_ISDIR(inode->i_mode)) {
342 inode->i_op = &ll_dir_inode_operations;
343 inode->i_fop = &ll_dir_operations;
344 inode->i_mapping->a_ops = &ll_dir_aops;
346 } else if (S_ISLNK(inode->i_mode)) {
347 if (inode->i_blocks) {
348 inode->i_op = &ll_symlink_inode_operations;
349 inode->i_mapping->a_ops = &ll_aops;
351 inode->i_op = &ll_fast_symlink_inode_operations;
355 init_special_inode(inode, inode->i_mode,
356 ((int *)ll_i2info(inode)->lli_inline)[0]);
363 /* exported operations */
364 struct super_operations ll_super_operations =
366 read_inode2: ll_read_inode2,
367 // put_inode: ll_put_inode,
368 // delete_inode: ll_delete_inode,
369 put_super: ll_put_super,
373 struct file_system_type lustre_light_fs_type = {
374 "lustre_light", 0, ll_read_super, NULL
377 static int __init init_lustre_light(void)
379 printk(KERN_INFO "Lustre Light 0.0.1, braam@clusterfs.com\n");
381 return register_filesystem(&lustre_light_fs_type);
384 static void __exit exit_lustre_light(void)
386 unregister_filesystem(&lustre_light_fs_type);
389 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
390 MODULE_DESCRIPTION("Lustre Light Client File System v1.0");
391 MODULE_LICENSE("GPL");
393 module_init(init_lustre_light);
394 module_exit(exit_lustre_light);