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>
23 kmem_cache_t *ll_file_data_slab;
24 extern struct address_space_operations ll_aops;
25 extern struct address_space_operations ll_dir_aops;
26 struct super_operations ll_super_operations;
28 extern int ll_recover(struct recovd_data *, int);
29 extern int ll_commitcbd_setup(struct ll_sb_info *);
30 extern int ll_commitcbd_cleanup(struct ll_sb_info *);
32 static char *ll_read_opt(const char *opt, char *data)
38 CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
39 if ( strncmp(opt, data, strlen(opt)) )
41 if ( (value = strchr(data, '=')) == NULL )
45 OBD_ALLOC(retval, strlen(value) + 1);
47 CERROR("out of memory!\n");
51 memcpy(retval, value, strlen(value)+1);
52 CDEBUG(D_SUPER, "Assigned option: %s, value %s\n", opt, retval);
56 static int ll_set_opt(const char *opt, char *data, int fl)
60 CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
61 if ( strncmp(opt, data, strlen(opt)) )
67 static void ll_options(char *options, char **ost, char **mds, int *flags)
77 for (this_char = strtok (options, ",");
79 this_char = strtok (NULL, ",")) {
80 CDEBUG(D_SUPER, "this_char %s\n", this_char);
81 if ( (!*ost && (*ost = ll_read_opt("osc", this_char)))||
82 (!*mds && (*mds = ll_read_opt("mdc", this_char)))||
83 (!(*flags & LL_SBI_NOLCK) && ((*flags) = (*flags) |
84 ll_set_opt("nolock", this_char, LL_SBI_NOLCK))) )
91 #define log2(n) ffz(~(n))
94 static struct super_block * ll_read_super(struct super_block *sb,
95 void *data, int silent)
97 struct inode *root = 0;
98 struct obd_device *obd;
99 struct ll_sb_info *sbi;
103 struct ll_fid rootfid;
104 struct obd_statfs osfs;
105 __u64 last_committed;
107 struct ptlrpc_request *request = NULL;
108 struct ptlrpc_connection *mdc_conn;
109 struct ll_read_inode2_cookie lic;
115 OBD_ALLOC(sbi, sizeof(*sbi));
121 INIT_LIST_HEAD(&sbi->ll_conn_chain);
122 sbi->ll_mount_epoch = 0;
123 generate_random_uuid(uuid);
124 class_uuid_unparse(uuid, sbi->ll_sb_uuid);
126 sb->u.generic_sbp = sbi;
128 ll_options(data, &osc, &mdc, &sbi->ll_flags);
132 GOTO(out_free, sb = NULL);
137 GOTO(out_free, sb = NULL);
140 obd = class_uuid2obd(mdc);
142 CERROR("MDC %s: not setup or attached\n", mdc);
143 GOTO(out_free, sb = NULL);
146 err = obd_connect(&sbi->ll_mdc_conn, obd, sbi->ll_sb_uuid,
147 ptlrpc_recovd, ll_recover);
149 CERROR("cannot connect to %s: rc = %d\n", mdc, err);
150 GOTO(out_free, sb = NULL);
153 #warning Peter: is this the right place to raise the connection level?
154 mdc_conn = sbi2mdc(sbi)->cl_import.imp_connection;
155 mdc_conn->c_level = LUSTRE_CONN_FULL;
156 list_add(&mdc_conn->c_sb_chain, &sbi->ll_conn_chain);
158 obd = class_uuid2obd(osc);
160 CERROR("OSC %s: not setup or attached\n", osc);
161 GOTO(out_mdc, sb = NULL);
164 err = obd_connect(&sbi->ll_osc_conn, obd, sbi->ll_sb_uuid,
165 ptlrpc_recovd, ll_recover);
167 CERROR("cannot connect to %s: rc = %d\n", osc, err);
168 GOTO(out_mdc, sb = NULL);
171 /* XXX: need to store the last_* values somewhere */
172 err = mdc_getstatus(&sbi->ll_mdc_conn, &rootfid, &last_committed,
173 &last_xid, &request);
174 ptlrpc_req_finished(request);
176 CERROR("cannot mds_connect: rc = %d\n", err);
177 GOTO(out_mdc, sb = NULL);
179 CDEBUG(D_SUPER, "rootfid %Ld\n", (unsigned long long)rootfid.id);
180 sbi->ll_rootino = rootfid.id;
182 memset(&osfs, 0, sizeof(osfs));
184 err = mdc_statfs(&sbi->ll_mdc_conn, &osfs, &request);
185 ptlrpc_req_finished(request);
186 sb->s_blocksize = osfs.os_bsize;
187 sb->s_blocksize_bits = log2(osfs.os_bsize);
188 sb->s_magic = LL_SUPER_MAGIC;
189 sb->s_maxbytes = (1ULL << (32 + 9)) - osfs.os_bsize;
191 sb->s_op = &ll_super_operations;
193 /* make root inode */
195 err = mdc_getattr(&sbi->ll_mdc_conn, sbi->ll_rootino, S_IFDIR,
196 OBD_MD_FLNOTOBD|OBD_MD_FLBLOCKS, 0, &request);
198 CERROR("mdc_getattr failed for root: rc = %d\n", err);
199 GOTO(out_request, sb = NULL);
202 /* initialize committed transaction callback daemon */
203 spin_lock_init(&sbi->ll_commitcbd_lock);
204 init_waitqueue_head(&sbi->ll_commitcbd_waitq);
205 init_waitqueue_head(&sbi->ll_commitcbd_ctl_waitq);
206 sbi->ll_commitcbd_flags = 0;
207 err = ll_commitcbd_setup(sbi);
209 CERROR("failed to start commit callback daemon: rc = %d\n",err);
210 GOTO(out_request, sb = NULL);
213 lic.lic_body = lustre_msg_buf(request->rq_repmsg, 0);
215 root = iget4(sb, sbi->ll_rootino, NULL, &lic);
218 sb->s_root = d_alloc_root(root);
220 CERROR("lustre_lite: bad iget4 for root\n");
221 GOTO(out_cdb, sb = NULL);
224 ptlrpc_req_finished(request);
228 OBD_FREE(mdc, strlen(mdc) + 1);
230 OBD_FREE(osc, strlen(osc) + 1);
235 ll_commitcbd_cleanup(sbi);
237 ptlrpc_req_finished(request);
238 obd_disconnect(&sbi->ll_osc_conn);
240 obd_disconnect(&sbi->ll_mdc_conn);
242 OBD_FREE(sbi, sizeof(*sbi));
246 } /* ll_read_super */
248 static void ll_put_super(struct super_block *sb)
250 struct ll_sb_info *sbi = ll_s2sbi(sb);
253 list_del(&sbi->ll_conn_chain);
254 ll_commitcbd_cleanup(sbi);
255 obd_disconnect(&sbi->ll_osc_conn);
256 obd_disconnect(&sbi->ll_mdc_conn);
257 OBD_FREE(sbi, sizeof(*sbi));
263 static void ll_clear_inode(struct inode *inode)
267 if (atomic_read(&inode->i_count) == 0) {
268 struct ll_inode_info *lli = ll_i2info(inode);
269 struct lov_stripe_md *lsm = lli->lli_smd;
270 char *symlink_name = lli->lli_symlink_name;
273 OBD_FREE(lsm, ll_ost_easize(inode->i_sb));
277 OBD_FREE(symlink_name, strlen(symlink_name) + 1);
278 lli->lli_symlink_name = NULL;
284 static void ll_delete_inode(struct inode *inode)
287 if (S_ISREG(inode->i_mode)) {
290 struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
295 if (lsm->lsm_object_id == 0) {
296 CERROR("This really happens\n");
297 /* No obdo was ever created */
305 oa->o_id = lsm->lsm_object_id;
306 oa->o_easize = ll_mds_easize(inode->i_sb);
307 oa->o_mode = inode->i_mode;
308 oa->o_valid = OBD_MD_FLID | OBD_MD_FLEASIZE | OBD_MD_FLTYPE;
310 err = obd_destroy(ll_i2obdconn(inode), oa, lsm);
312 CDEBUG(D_SUPER, "obd destroy of objid "LPX64" error %d\n",
313 lsm->lsm_object_id, err);
320 /* like inode_setattr, but doesn't mark the inode dirty */
321 static int ll_attr2inode(struct inode * inode, struct iattr * attr, int trunc)
323 unsigned int ia_valid = attr->ia_valid;
326 if ((ia_valid & ATTR_SIZE) && trunc) {
327 error = vmtruncate(inode, attr->ia_size);
330 } else if (ia_valid & ATTR_SIZE)
331 inode->i_size = attr->ia_size;
333 if (ia_valid & ATTR_UID)
334 inode->i_uid = attr->ia_uid;
335 if (ia_valid & ATTR_GID)
336 inode->i_gid = attr->ia_gid;
337 if (ia_valid & ATTR_ATIME)
338 inode->i_atime = attr->ia_atime;
339 if (ia_valid & ATTR_MTIME)
340 inode->i_mtime = attr->ia_mtime;
341 if (ia_valid & ATTR_CTIME)
342 inode->i_ctime = attr->ia_ctime;
343 if (ia_valid & ATTR_MODE) {
344 inode->i_mode = attr->ia_mode;
345 if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID))
346 inode->i_mode &= ~S_ISGID;
352 int ll_inode_setattr(struct inode *inode, struct iattr *attr, int do_trunc)
354 struct ptlrpc_request *request = NULL;
355 struct ll_sb_info *sbi = ll_i2sbi(inode);
360 /* change incore inode */
361 ll_attr2inode(inode, attr, do_trunc);
363 err = mdc_setattr(&sbi->ll_mdc_conn, inode, attr, &request);
365 CERROR("mdc_setattr fails (%d)\n", err);
367 ptlrpc_req_finished(request);
372 int ll_setattr(struct dentry *de, struct iattr *attr)
374 int rc = inode_change_ok(de->d_inode, attr);
379 return ll_inode_setattr(de->d_inode, attr, 1);
382 static int ll_statfs(struct super_block *sb, struct statfs *sfs)
384 struct ptlrpc_request *request = NULL;
385 struct ll_sb_info *sbi = ll_s2sbi(sb);
386 struct obd_statfs osfs;
390 memset(sfs, 0, sizeof(*sfs));
391 rc = mdc_statfs(&sbi->ll_mdc_conn, &osfs, &request);
392 statfs_unpack(sfs, &osfs);
393 ptlrpc_req_finished(request);
395 CERROR("mdc_statfs fails: rc = %d\n", rc);
397 CDEBUG(D_SUPER, "mdc_statfs shows blocks "LPU64"/"LPU64
398 " objects "LPU64"/"LPU64"\n",
399 osfs.os_bavail, osfs.os_blocks,
400 osfs.os_ffree, osfs.os_files);
402 /* temporary until mds_statfs returns statfs info for all OSTs */
404 rc = obd_statfs(&sbi->ll_osc_conn, &osfs);
406 CERROR("obd_statfs fails: rc = %d\n", rc);
409 CDEBUG(D_SUPER, "obd_statfs shows blocks "LPU64"/"LPU64
410 " objects "LPU64"/"LPU64"\n",
411 osfs.os_bavail, osfs.os_blocks,
412 osfs.os_ffree, osfs.os_files);
414 while (osfs.os_blocks > ~0UL) {
417 osfs.os_blocks >>= 1;
419 osfs.os_bavail >>= 1;
421 sfs->f_blocks = osfs.os_blocks;
422 sfs->f_bfree = osfs.os_bfree;
423 sfs->f_bavail = osfs.os_bavail;
424 if (osfs.os_ffree < (__u64)sfs->f_ffree)
425 sfs->f_ffree = osfs.os_ffree;
432 void ll_update_inode(struct inode *inode, struct mds_body *body)
434 if (body->valid & OBD_MD_FLID)
435 inode->i_ino = body->ino;
436 if (body->valid & OBD_MD_FLATIME)
437 inode->i_atime = body->atime;
438 if (body->valid & OBD_MD_FLMTIME)
439 inode->i_mtime = body->mtime;
440 if (body->valid & OBD_MD_FLCTIME)
441 inode->i_ctime = body->ctime;
442 if (body->valid & OBD_MD_FLMODE)
443 inode->i_mode = (inode->i_mode & S_IFMT)|(body->mode & ~S_IFMT);
444 if (body->valid & OBD_MD_FLTYPE)
445 inode->i_mode = (inode->i_mode & ~S_IFMT)|(body->mode & S_IFMT);
446 if (body->valid & OBD_MD_FLUID)
447 inode->i_uid = body->uid;
448 if (body->valid & OBD_MD_FLGID)
449 inode->i_gid = body->gid;
450 if (body->valid & OBD_MD_FLFLAGS)
451 inode->i_flags = body->flags;
452 if (body->valid & OBD_MD_FLNLINK)
453 inode->i_nlink = body->nlink;
454 if (body->valid & OBD_MD_FLGENER)
455 inode->i_generation = body->generation;
456 if (body->valid & OBD_MD_FLRDEV)
457 inode->i_rdev = body->rdev;
458 if (body->valid & OBD_MD_FLSIZE)
459 inode->i_size = body->size;
462 static void ll_read_inode2(struct inode *inode, void *opaque)
464 struct ll_read_inode2_cookie *lic = opaque;
465 struct mds_body *body = lic->lic_body;
466 struct ll_inode_info *lli = ll_i2info(inode);
469 sema_init(&lli->lli_open_sem, 1);
470 lli->lli_mount_epoch = ll_i2sbi(inode)->ll_mount_epoch;
472 /* core attributes first */
473 ll_update_inode(inode, body);
475 //if (body->valid & OBD_MD_FLEASIZE)
476 if (lic && lic->lic_lmm) {
477 struct lov_mds_md *lmm = lic->lic_lmm;
480 if (lmm->lmm_easize != ll_mds_easize(inode->i_sb)) {
481 CERROR("Striping metadata size error %ld\n",
485 size = ll_ost_easize(inode->i_sb);
486 OBD_ALLOC(lli->lli_smd, size);
488 CERROR("No memory for %d\n", size);
491 lov_unpackmd(lli->lli_smd, lmm);
496 /* Get the authoritative file size */
497 if (lli->lli_smd && (inode->i_mode & S_IFREG)) {
500 rc = ll_file_size(inode, lli->lli_smd);
502 CERROR("ll_file_size: %d\n", rc);
503 /* FIXME: need to somehow prevent inode creation */
508 /* OIDEBUG(inode); */
510 if (S_ISREG(inode->i_mode)) {
511 inode->i_op = &ll_file_inode_operations;
512 inode->i_fop = &ll_file_operations;
513 inode->i_mapping->a_ops = &ll_aops;
515 } else if (S_ISDIR(inode->i_mode)) {
516 inode->i_op = &ll_dir_inode_operations;
517 inode->i_fop = &ll_dir_operations;
518 inode->i_mapping->a_ops = &ll_dir_aops;
520 } else if (S_ISLNK(inode->i_mode)) {
521 inode->i_op = &ll_fast_symlink_inode_operations;
524 init_special_inode(inode, inode->i_mode, inode->i_rdev);
529 static inline void invalidate_request_list(struct list_head *req_list)
531 struct list_head *tmp, *n;
532 list_for_each_safe(tmp, n, req_list) {
533 struct ptlrpc_request *req =
534 list_entry(tmp, struct ptlrpc_request, rq_list);
535 CERROR("invalidating req xid %d op %d to %s:%d\n",
536 (unsigned long long)req->rq_xid, req->rq_reqmsg->opc,
537 req->rq_connection->c_remote_uuid,
538 req->rq_import->imp_client->cli_request_portal);
539 req->rq_flags |= PTL_RPC_FL_ERR;
540 wake_up(&req->rq_wait_for_rep);
544 void ll_umount_begin(struct super_block *sb)
546 struct ll_sb_info *sbi = ll_s2sbi(sb);
547 struct list_head *ctmp;
551 list_for_each(ctmp, &sbi->ll_conn_chain) {
552 struct ptlrpc_connection *conn;
553 conn = list_entry(ctmp, struct ptlrpc_connection, c_sb_chain);
555 spin_lock(&conn->c_lock);
556 conn->c_flags |= CONN_INVALID;
557 invalidate_request_list(&conn->c_sending_head);
558 invalidate_request_list(&conn->c_delayed_head);
559 spin_unlock(&conn->c_lock);
565 /* exported operations */
566 struct super_operations ll_super_operations =
568 read_inode2: ll_read_inode2,
569 clear_inode: ll_clear_inode,
570 delete_inode: ll_delete_inode,
571 put_super: ll_put_super,
573 umount_begin: ll_umount_begin
576 struct file_system_type lustre_lite_fs_type = {
577 "lustre_lite", 0, ll_read_super, NULL
580 static int __init init_lustre_lite(void)
582 printk(KERN_INFO "Lustre Lite 0.5.14, info@clusterfs.com\n");
583 ll_file_data_slab = kmem_cache_create("ll_file_data",
584 sizeof(struct ll_file_data), 0,
585 SLAB_HWCACHE_ALIGN, NULL, NULL);
586 if (ll_file_data_slab == NULL)
588 return register_filesystem(&lustre_lite_fs_type);
591 static void __exit exit_lustre_lite(void)
593 unregister_filesystem(&lustre_lite_fs_type);
594 kmem_cache_destroy(ll_file_data_slab);
597 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
598 MODULE_DESCRIPTION("Lustre Lite Client File System v1.0");
599 MODULE_LICENSE("GPL");
601 module_init(init_lustre_lite);
602 module_exit(exit_lustre_lite);