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 <asm/segment.h>
33 #define DEBUG_SUBSYSTEM S_LLIGHT
35 #include <linux/obd_support.h>
36 #include <linux/obd_class.h>
37 #include <linux/lustre_light.h>
39 extern struct address_space_operations ll_aops;
40 extern struct address_space_operations ll_dir_aops;
41 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))) )
95 static struct super_block * ll_read_super(struct super_block *sb,
96 void *data, int silent)
98 struct inode *root = 0;
99 struct ll_sb_info *sbi;
101 char *version = NULL;
106 struct ptlrep_hdr *hdr = NULL;
111 OBD_ALLOC(sbi, sizeof(*sbi));
116 memset(sbi, 0, sizeof(*sbi));
117 sb->u.generic_sbp = (struct ll_sb_info *) sbi;
119 ll_options(data, &device, &version);
122 CERROR("no device\n");
127 devno = simple_strtoul(device, NULL, 0);
128 if ( devno >= MAX_OBD_DEVICES ) {
129 CERROR("device of %s too high\n", device);
134 sbi->ll_conn.oc_dev = &obd_dev[devno];
135 err = obd_connect(&sbi->ll_conn);
137 CERROR("cannot connect to %s\n", device);
143 err = mdc_create_client("mds", &sbi->ll_mds_client);
145 CERROR("cannot find MDS\n");
152 sb->s_maxbytes = 1LL << 36;
153 sb->s_blocksize = PAGE_SIZE;
154 sb->s_blocksize_bits = (unsigned char)PAGE_SHIFT;
155 sb->s_magic = LL_SUPER_MAGIC;
156 sb->s_op = &ll_super_operations;
158 /* make root inode */
159 err = mdc_getattr(&sbi->ll_mds_client, sbi->ll_rootino, S_IFDIR,
160 OBD_MD_FLNOTOBD|OBD_MD_FLBLOCKS,
163 CERROR("mds_getattr failed for root %d\n", err);
168 root = iget4(sb, sbi->ll_rootino, NULL, rep);
170 sb->s_root = d_alloc_root(root);
172 CERROR("lustre_light: bad iget4 for root\n");
179 /* FIXME: sigh, another stupid hardcoded size */
180 OBD_FREE(hdr, sizeof(struct ptlrep_hdr) +
181 sizeof(struct mds_rep));
183 OBD_FREE(device, strlen(device) + 1);
185 OBD_FREE(version, strlen(version) + 1);
186 if (!sb && connected)
187 obd_disconnect(&sbi->ll_conn);
197 } /* ll_read_super */
199 static void ll_put_super(struct super_block *sb)
203 obd_disconnect(ID(sb));
204 OBD_FREE(sb->u.generic_sbp, sizeof(struct ll_sb_info));
210 extern inline struct obdo * ll_oa_from_inode(struct inode *inode, int valid);
211 static void ll_delete_inode(struct inode *inode)
213 if (S_ISREG(inode->i_mode)) {
216 oa = ll_oa_from_inode(inode, OBD_MD_FLNOTOBD);
218 CERROR("no memory\n");
221 err = obd_destroy(IID(inode), oa);
222 CDEBUG(D_INODE, "obd destroy of %Ld error %d\n",
230 /* like inode_setattr, but doesn't mark the inode dirty */
231 static int ll_attr2inode(struct inode * inode, struct iattr * attr, int trunc)
233 unsigned int ia_valid = attr->ia_valid;
236 if ((ia_valid & ATTR_SIZE) && trunc ) {
237 error = vmtruncate(inode, attr->ia_size);
240 } else if (ia_valid & ATTR_SIZE) {
241 inode->i_size = attr->ia_size;
244 if (ia_valid & ATTR_UID)
245 inode->i_uid = attr->ia_uid;
246 if (ia_valid & ATTR_GID)
247 inode->i_gid = attr->ia_gid;
248 if (ia_valid & ATTR_ATIME)
249 inode->i_atime = attr->ia_atime;
250 if (ia_valid & ATTR_MTIME)
251 inode->i_mtime = attr->ia_mtime;
252 if (ia_valid & ATTR_CTIME)
253 inode->i_ctime = attr->ia_ctime;
254 if (ia_valid & ATTR_MODE) {
255 inode->i_mode = attr->ia_mode;
256 if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID))
257 inode->i_mode &= ~S_ISGID;
263 int ll_inode_setattr(struct inode *inode, struct iattr *attr, int do_trunc)
265 struct ptlrep_hdr *hdr = NULL;
266 struct ll_sb_info *sbi = ll_i2sbi(inode);
271 /* change incore inode */
272 ll_attr2inode(inode, attr, do_trunc);
274 err = mdc_setattr(&sbi->ll_mds_client, inode, attr, NULL, &hdr);
276 CERROR("ll_setattr fails (%d)\n", err);
282 int ll_setattr(struct dentry *de, struct iattr *attr)
284 return ll_inode_setattr(de->d_inode, attr, 1);
287 static int ll_statfs(struct super_block *sb, struct statfs *buf)
294 err = obd_statfs(ID(sb), &tmp);
296 CERROR("obd_statfs fails (%d)\n", err);
299 memcpy(buf, &tmp, sizeof(*buf));
300 CDEBUG(D_SUPER, "statfs returns avail %ld\n", tmp.f_bavail);
306 static void inline ll_to_inode(struct inode *dst, struct mds_rep *rep)
308 struct ll_inode_info *ii =
309 (struct ll_inode_info *) &dst->u.generic_ip;
311 /* core attributes first */
312 if ( rep->valid & OBD_MD_FLID )
313 dst->i_ino = rep->ino;
314 if ( rep->valid & OBD_MD_FLATIME )
315 dst->i_atime = rep->atime;
316 if ( rep->valid & OBD_MD_FLMTIME )
317 dst->i_mtime = rep->mtime;
318 if ( rep->valid & OBD_MD_FLCTIME )
319 dst->i_ctime = rep->ctime;
320 if ( rep->valid & OBD_MD_FLSIZE )
321 dst->i_size = rep->size;
322 if ( rep->valid & OBD_MD_FLMODE )
323 dst->i_mode = rep->mode;
324 if ( rep->valid & OBD_MD_FLUID )
325 dst->i_uid = rep->uid;
326 if ( rep->valid & OBD_MD_FLGID )
327 dst->i_gid = rep->gid;
328 if ( rep->valid & OBD_MD_FLFLAGS )
329 dst->i_flags = rep->flags;
330 if ( rep->valid & OBD_MD_FLNLINK )
331 dst->i_nlink = rep->nlink;
332 if ( rep->valid & OBD_MD_FLGENER )
333 dst->i_generation = rep->generation;
335 /* this will become more elaborate for striping etc */
336 if (rep->valid & OBD_MD_FLOBJID)
337 ii->lli_objid = rep->objid;
340 if (obdo_has_inline(oa)) {
341 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) ||
342 S_ISFIFO(inode->i_mode)) {
343 obd_rdev rdev = *((obd_rdev *)oa->o_inline);
345 "copying device %x from obdo to inode\n", rdev);
346 init_special_inode(inode, inode->i_mode, rdev);
348 CDEBUG(D_INFO, "copying inline from obdo to inode\n");
349 memcpy(oinfo->lli_inline, oa->o_inline, OBD_INLINESZ);
351 oinfo->lli_flags |= OBD_FL_INLINEDATA;
356 static inline void ll_read_inode2(struct inode *inode, void *opaque)
358 struct mds_rep *rep = opaque;
361 ll_to_inode(inode, rep);
363 /* OIDEBUG(inode); */
365 if (S_ISREG(inode->i_mode)) {
366 inode->i_op = &ll_file_inode_operations;
367 inode->i_fop = &ll_file_operations;
368 inode->i_mapping->a_ops = &ll_aops;
370 } else if (S_ISDIR(inode->i_mode)) {
371 inode->i_op = &ll_dir_inode_operations;
372 inode->i_fop = &ll_dir_operations;
373 inode->i_mapping->a_ops = &ll_dir_aops;
375 } else if (S_ISLNK(inode->i_mode)) {
376 inode->i_op = &ll_fast_symlink_inode_operations;
379 init_special_inode(inode, inode->i_mode,
380 ((int *)ll_i2info(inode)->lli_inline)[0]);
387 /* exported operations */
388 struct super_operations ll_super_operations =
390 read_inode2: ll_read_inode2,
391 delete_inode: ll_delete_inode,
392 put_super: ll_put_super,
396 struct file_system_type lustre_light_fs_type = {
397 "lustre_light", 0, ll_read_super, NULL
400 static int __init init_lustre_light(void)
402 printk(KERN_INFO "Lustre Light 0.0.1, braam@clusterfs.com\n");
404 return register_filesystem(&lustre_light_fs_type);
407 static void __exit exit_lustre_light(void)
409 unregister_filesystem(&lustre_light_fs_type);
412 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
413 MODULE_DESCRIPTION("Lustre Light Client File System v1.0");
414 MODULE_LICENSE("GPL");
416 module_init(init_lustre_light);
417 module_exit(exit_lustre_light);