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) 2002 Cluster File Systems, Inc.
12 #define DEBUG_SUBSYSTEM S_LLITE
14 #include <linux/module.h>
15 #include <linux/random.h>
16 #include <linux/lustre_lite.h>
17 #include <linux/lustre_ha.h>
18 #include <linux/obd_lov.h>
19 #include <linux/lustre_dlm.h>
20 #include <linux/init.h>
22 kmem_cache_t *ll_file_data_slab;
23 extern struct address_space_operations ll_aops;
24 extern struct address_space_operations ll_dir_aops;
25 struct super_operations ll_super_operations;
27 extern int ll_recover(struct recovd_data *, int);
28 extern int ll_commitcbd_setup(struct ll_sb_info *);
29 extern int ll_commitcbd_cleanup(struct ll_sb_info *);
31 static char *ll_read_opt(const char *opt, char *data)
37 CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
38 if ( strncmp(opt, data, strlen(opt)) )
40 if ( (value = strchr(data, '=')) == NULL )
44 OBD_ALLOC(retval, strlen(value) + 1);
46 CERROR("out of memory!\n");
50 memcpy(retval, value, strlen(value)+1);
51 CDEBUG(D_SUPER, "Assigned option: %s, value %s\n", opt, retval);
55 static void ll_options(char *options, char **ost, char **mds)
65 for (this_char = strtok (options, ",");
67 this_char = strtok (NULL, ",")) {
68 CDEBUG(D_SUPER, "this_char %s\n", this_char);
69 if ( (!*ost && (*ost = ll_read_opt("osc", this_char)))||
70 (!*mds && (*mds = ll_read_opt("mdc", this_char))) )
77 #define log2(n) ffz(~(n))
80 static struct super_block * ll_read_super(struct super_block *sb,
81 void *data, int silent)
83 struct inode *root = 0;
84 struct obd_device *obd;
85 struct ll_sb_info *sbi;
89 struct ll_fid rootfid;
93 struct ptlrpc_request *request = NULL;
94 struct ll_inode_md md;
100 OBD_ALLOC(sbi, sizeof(*sbi));
106 generate_random_uuid(uuid);
107 class_uuid_unparse(uuid, sbi->ll_sb_uuid);
109 sb->u.generic_sbp = sbi;
111 ll_options(data, &osc, &mdc);
115 GOTO(out_free, sb = NULL);
120 GOTO(out_free, sb = NULL);
123 obd = class_uuid2obd(mdc);
125 CERROR("MDC %s: not setup or attached\n", mdc);
126 GOTO(out_free, sb = NULL);
129 err = obd_connect(&sbi->ll_mdc_conn, obd, sbi->ll_sb_uuid);
131 CERROR("cannot connect to %s: rc = %d\n", mdc, err);
132 GOTO(out_free, sb = NULL);
135 #warning Peter: is this the right place to raise the connection level?
136 sbi2mdc(sbi)->cl_import.imp_connection->c_level = LUSTRE_CONN_FULL;
138 obd = class_uuid2obd(osc);
140 CERROR("OSC %s: not setup or attached\n", osc);
141 GOTO(out_mdc, sb = NULL);
143 err = obd_connect(&sbi->ll_osc_conn, obd, sbi->ll_sb_uuid);
145 CERROR("cannot connect to %s: rc = %d\n", osc, err);
146 GOTO(out_mdc, sb = NULL);
149 /* XXX: need to store the last_* values somewhere */
150 err = mdc_getstatus(&sbi->ll_mdc_conn, &rootfid, &last_committed,
151 &last_xid, &request);
152 ptlrpc_req_finished(request);
154 CERROR("cannot mds_connect: rc = %d\n", err);
155 GOTO(out_mdc, sb = NULL);
157 CDEBUG(D_SUPER, "rootfid %Ld\n", (unsigned long long)rootfid.id);
158 sbi->ll_rootino = rootfid.id;
160 memset(&sfs, 0, sizeof(sfs));
162 err = mdc_statfs(&sbi->ll_mdc_conn, &sfs, &request);
163 ptlrpc_req_finished(request);
164 sb->s_blocksize = sfs.f_bsize;
165 sb->s_blocksize_bits = log2(sfs.f_bsize);
166 sb->s_magic = LL_SUPER_MAGIC;
167 sb->s_maxbytes = (1ULL << (32 + 9)) - sfs.f_bsize;
169 sb->s_op = &ll_super_operations;
171 /* make root inode */
173 err = mdc_getattr(&sbi->ll_mdc_conn, sbi->ll_rootino, S_IFDIR,
174 OBD_MD_FLNOTOBD|OBD_MD_FLBLOCKS, 0, &request);
176 CERROR("mdc_getattr failed for root: rc = %d\n", err);
177 GOTO(out_request, sb = NULL);
180 /* initialize committed transaction callback daemon */
181 spin_lock_init(&sbi->ll_commitcbd_lock);
182 init_waitqueue_head(&sbi->ll_commitcbd_waitq);
183 init_waitqueue_head(&sbi->ll_commitcbd_ctl_waitq);
184 sbi->ll_commitcbd_flags = 0;
185 err = ll_commitcbd_setup(sbi);
187 CERROR("failed to start commit callback daemon: rc = %d\n",err);
188 GOTO(out_request, sb = NULL);
191 md.body = lustre_msg_buf(request->rq_repmsg, 0);
193 root = iget4(sb, sbi->ll_rootino, NULL, &md);
196 sb->s_root = d_alloc_root(root);
198 CERROR("lustre_lite: bad iget4 for root\n");
199 GOTO(out_cdb, sb = NULL);
202 ptlrpc_req_finished(request);
206 OBD_FREE(mdc, strlen(mdc) + 1);
208 OBD_FREE(osc, strlen(osc) + 1);
213 ll_commitcbd_cleanup(sbi);
215 ptlrpc_req_finished(request);
216 obd_disconnect(&sbi->ll_osc_conn);
218 obd_disconnect(&sbi->ll_mdc_conn);
220 OBD_FREE(sbi, sizeof(*sbi));
224 } /* ll_read_super */
226 static void ll_put_super(struct super_block *sb)
228 struct ll_sb_info *sbi = ll_s2sbi(sb);
230 ll_commitcbd_cleanup(sbi);
231 obd_disconnect(&sbi->ll_osc_conn);
232 obd_disconnect(&sbi->ll_mdc_conn);
233 OBD_FREE(sbi, sizeof(*sbi));
239 static void ll_clear_inode(struct inode *inode)
241 if (atomic_read(&inode->i_count) == 0) {
242 struct ll_inode_info *lli = ll_i2info(inode);
243 struct lov_stripe_md *md = lli->lli_smd;
244 char *symlink_name = lli->lli_symlink_name;
247 int size = sizeof(*md) +
248 md->lmd_stripe_count * sizeof(struct lov_oinfo);
253 OBD_FREE(symlink_name, strlen(symlink_name) + 1);
254 lli->lli_symlink_name = NULL;
259 static void ll_delete_inode(struct inode *inode)
261 if (S_ISREG(inode->i_mode)) {
264 struct lov_stripe_md *md = ll_i2info(inode)->lli_smd;
269 if (md->lmd_object_id == 0) {
270 CERROR("This really happens\n");
271 /* No obdo was ever created */
279 oa->o_id = md->lmd_object_id;
280 oa->o_easize = md->lmd_easize;
281 oa->o_mode = inode->i_mode;
282 oa->o_valid = OBD_MD_FLID | OBD_MD_FLEASIZE | OBD_MD_FLMODE;
284 err = obd_destroy(ll_i2obdconn(inode), oa, md);
286 CDEBUG(D_SUPER, "obd destroy of %Ld error %d\n",
287 md->lmd_object_id, err);
293 /* like inode_setattr, but doesn't mark the inode dirty */
294 static int ll_attr2inode(struct inode * inode, struct iattr * attr, int trunc)
296 unsigned int ia_valid = attr->ia_valid;
299 if ((ia_valid & ATTR_SIZE) && trunc) {
300 error = vmtruncate(inode, attr->ia_size);
303 } else if (ia_valid & ATTR_SIZE)
304 inode->i_size = attr->ia_size;
306 if (ia_valid & ATTR_UID)
307 inode->i_uid = attr->ia_uid;
308 if (ia_valid & ATTR_GID)
309 inode->i_gid = attr->ia_gid;
310 if (ia_valid & ATTR_ATIME)
311 inode->i_atime = attr->ia_atime;
312 if (ia_valid & ATTR_MTIME)
313 inode->i_mtime = attr->ia_mtime;
314 if (ia_valid & ATTR_CTIME)
315 inode->i_ctime = attr->ia_ctime;
316 if (ia_valid & ATTR_MODE) {
317 inode->i_mode = attr->ia_mode;
318 if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID))
319 inode->i_mode &= ~S_ISGID;
325 int ll_inode_setattr(struct inode *inode, struct iattr *attr, int do_trunc)
327 struct ptlrpc_request *request = NULL;
328 struct ll_sb_info *sbi = ll_i2sbi(inode);
333 /* change incore inode */
334 ll_attr2inode(inode, attr, do_trunc);
336 err = mdc_setattr(&sbi->ll_mdc_conn, inode, attr, &request);
338 CERROR("mdc_setattr fails (%d)\n", err);
340 ptlrpc_req_finished(request);
345 int ll_setattr(struct dentry *de, struct iattr *attr)
347 int rc = inode_change_ok(de->d_inode, attr);
352 return ll_inode_setattr(de->d_inode, attr, 1);
355 static int ll_statfs(struct super_block *sb, struct statfs *sfs)
357 struct ptlrpc_request *request = NULL;
358 struct ll_sb_info *sbi = ll_s2sbi(sb);
362 memset(sfs, 0, sizeof(*sfs));
363 rc = mdc_statfs(&sbi->ll_mdc_conn, sfs, &request);
364 ptlrpc_req_finished(request);
366 CERROR("obd_statfs fails: rc = %d\n", rc);
368 CDEBUG(D_SUPER, "statfs shows blocks %lu/%lu objects %lu/%lu\n",
369 sfs->f_bavail, sfs->f_blocks, sfs->f_ffree,sfs->f_files);
371 /* temporary until mds_statfs returns statfs info for all OSTs */
373 struct statfs obd_sfs;
375 rc = obd_statfs(&sbi->ll_osc_conn, &obd_sfs);
377 CERROR("obd_statfs fails: rc = %d\n", rc);
380 CDEBUG(D_SUPER, "obd_statfs returns blocks %lu/%lu, "
382 obd_sfs.f_bavail, obd_sfs.f_blocks,
383 obd_sfs.f_ffree, obd_sfs.f_files);
385 sfs->f_bfree = obd_sfs.f_bfree;
386 sfs->f_bavail = obd_sfs.f_bavail;
387 sfs->f_blocks = obd_sfs.f_blocks;
388 if (obd_sfs.f_ffree < sfs->f_ffree)
389 sfs->f_ffree = obd_sfs.f_ffree;
396 inline int ll_stripe_mds_md_size(struct super_block *sb)
398 struct client_obd *mdc = sbi2mdc(ll_s2sbi(sb));
399 return mdc->cl_max_mdsize;
402 static void ll_read_inode2(struct inode *inode, void *opaque)
404 struct ll_inode_md *md = opaque;
405 struct mds_body *body = md->body;
406 struct ll_inode_info *lli = ll_i2info(inode);
409 sema_init(&lli->lli_open_sem, 1);
411 /* core attributes first */
412 if (body->valid & OBD_MD_FLID)
413 inode->i_ino = body->ino;
414 if (body->valid & OBD_MD_FLATIME)
415 inode->i_atime = body->atime;
416 if (body->valid & OBD_MD_FLMTIME)
417 inode->i_mtime = body->mtime;
418 if (body->valid & OBD_MD_FLCTIME)
419 inode->i_ctime = body->ctime;
420 if (body->valid & OBD_MD_FLMODE)
421 inode->i_mode = body->mode;
422 if (body->valid & OBD_MD_FLUID)
423 inode->i_uid = body->uid;
424 if (body->valid & OBD_MD_FLGID)
425 inode->i_gid = body->gid;
426 if (body->valid & OBD_MD_FLFLAGS)
427 inode->i_flags = body->flags;
428 if (body->valid & OBD_MD_FLNLINK)
429 inode->i_nlink = body->nlink;
430 if (body->valid & OBD_MD_FLGENER)
431 inode->i_generation = body->generation;
432 if (body->valid & OBD_MD_FLRDEV)
433 inode->i_rdev = body->extra;
434 if (body->valid & OBD_MD_FLSIZE)
435 inode->i_size = body->size;
438 //if (body->valid & OBD_MD_FLEASIZE)
439 if (md && md->md && md->md->lmd_stripe_count) {
440 struct lov_mds_md *smd = md->md;
442 if (md->md->lmd_easize != ll_stripe_mds_md_size(inode->i_sb)) {
443 CERROR("Striping metadata size error %ld\n",
447 size = sizeof(*lli->lli_smd) +
448 md->md->lmd_stripe_count * sizeof(struct lov_oinfo);
449 OBD_ALLOC(lli->lli_smd, size);
451 CERROR("No memory for %d\n", size);
454 lov_unpackmd(lli->lli_smd, smd);
459 /* Get the authoritative file size */
460 if (lli->lli_smd && (inode->i_mode & S_IFREG)) {
463 rc = ll_file_size(inode, lli->lli_smd);
465 CERROR("ll_file_size: %d\n", rc);
466 /* FIXME: need to somehow prevent inode creation */
471 /* OIDEBUG(inode); */
473 if (S_ISREG(inode->i_mode)) {
474 inode->i_op = &ll_file_inode_operations;
475 inode->i_fop = &ll_file_operations;
476 inode->i_mapping->a_ops = &ll_aops;
478 } else if (S_ISDIR(inode->i_mode)) {
479 inode->i_op = &ll_dir_inode_operations;
480 inode->i_fop = &ll_dir_operations;
481 inode->i_mapping->a_ops = &ll_dir_aops;
483 } else if (S_ISLNK(inode->i_mode)) {
484 inode->i_op = &ll_fast_symlink_inode_operations;
487 init_special_inode(inode, inode->i_mode, inode->i_rdev);
494 /* exported operations */
495 struct super_operations ll_super_operations =
497 read_inode2: ll_read_inode2,
498 clear_inode: ll_clear_inode,
499 delete_inode: ll_delete_inode,
500 put_super: ll_put_super,
504 struct file_system_type lustre_lite_fs_type = {
505 "lustre_lite", 0, ll_read_super, NULL
508 static int __init init_lustre_lite(void)
510 printk(KERN_INFO "Lustre Lite 0.0.1, info@clusterfs.com\n");
511 ll_file_data_slab = kmem_cache_create("ll_file_data",
512 sizeof(struct ll_file_data), 0,
513 SLAB_HWCACHE_ALIGN, NULL, NULL);
514 if (ll_file_data_slab == NULL)
516 return register_filesystem(&lustre_lite_fs_type);
519 static void __exit exit_lustre_lite(void)
521 unregister_filesystem(&lustre_lite_fs_type);
522 kmem_cache_destroy(ll_file_data_slab);
525 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
526 MODULE_DESCRIPTION("Lustre Lite Client File System v1.0");
527 MODULE_LICENSE("GPL");
529 module_init(init_lustre_lite);
530 module_exit(exit_lustre_lite);