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);
134 recovd_conn_manage(obd->u.cli.cl_import.imp_connection,
135 ptlrpc_recovd, ll_recover);
137 #warning Peter: is this the right place to raise the connection level?
138 sbi2mdc(sbi)->cl_import.imp_connection->c_level = LUSTRE_CONN_FULL;
140 obd = class_uuid2obd(osc);
142 CERROR("OSC %s: not setup or attached\n", osc);
143 GOTO(out_mdc, sb = NULL);
145 err = obd_connect(&sbi->ll_osc_conn, obd, sbi->ll_sb_uuid);
147 CERROR("cannot connect to %s: rc = %d\n", osc, err);
148 GOTO(out_mdc, sb = NULL);
150 recovd_conn_manage(obd->u.cli.cl_import.imp_connection,
151 ptlrpc_recovd, ll_recover);
153 /* XXX: need to store the last_* values somewhere */
154 err = mdc_getstatus(&sbi->ll_mdc_conn, &rootfid, &last_committed,
155 &last_xid, &request);
156 ptlrpc_req_finished(request);
158 CERROR("cannot mds_connect: rc = %d\n", err);
159 GOTO(out_mdc, sb = NULL);
161 CDEBUG(D_SUPER, "rootfid %Ld\n", (unsigned long long)rootfid.id);
162 sbi->ll_rootino = rootfid.id;
164 memset(&sfs, 0, sizeof(sfs));
166 err = mdc_statfs(&sbi->ll_mdc_conn, &sfs, &request);
167 ptlrpc_req_finished(request);
168 sb->s_blocksize = sfs.f_bsize;
169 sb->s_blocksize_bits = log2(sfs.f_bsize);
170 sb->s_magic = LL_SUPER_MAGIC;
171 sb->s_maxbytes = (1ULL << (32 + 9)) - sfs.f_bsize;
173 sb->s_op = &ll_super_operations;
175 /* make root inode */
177 err = mdc_getattr(&sbi->ll_mdc_conn, sbi->ll_rootino, S_IFDIR,
178 OBD_MD_FLNOTOBD|OBD_MD_FLBLOCKS, 0, &request);
180 CERROR("mdc_getattr failed for root: rc = %d\n", err);
181 GOTO(out_request, sb = NULL);
184 /* initialize committed transaction callback daemon */
185 spin_lock_init(&sbi->ll_commitcbd_lock);
186 init_waitqueue_head(&sbi->ll_commitcbd_waitq);
187 init_waitqueue_head(&sbi->ll_commitcbd_ctl_waitq);
188 sbi->ll_commitcbd_flags = 0;
189 err = ll_commitcbd_setup(sbi);
191 CERROR("failed to start commit callback daemon: rc = %d\n",err);
192 GOTO(out_request, sb = NULL);
195 md.body = lustre_msg_buf(request->rq_repmsg, 0);
197 root = iget4(sb, sbi->ll_rootino, NULL, &md);
200 sb->s_root = d_alloc_root(root);
202 CERROR("lustre_lite: bad iget4 for root\n");
203 GOTO(out_cdb, sb = NULL);
206 ptlrpc_req_finished(request);
210 OBD_FREE(mdc, strlen(mdc) + 1);
212 OBD_FREE(osc, strlen(osc) + 1);
217 ll_commitcbd_cleanup(sbi);
219 ptlrpc_req_finished(request);
220 obd_disconnect(&sbi->ll_osc_conn);
222 obd_disconnect(&sbi->ll_mdc_conn);
224 OBD_FREE(sbi, sizeof(*sbi));
228 } /* ll_read_super */
230 static void ll_put_super(struct super_block *sb)
232 struct ll_sb_info *sbi = ll_s2sbi(sb);
234 ll_commitcbd_cleanup(sbi);
235 obd_disconnect(&sbi->ll_osc_conn);
236 obd_disconnect(&sbi->ll_mdc_conn);
237 OBD_FREE(sbi, sizeof(*sbi));
243 static void ll_clear_inode(struct inode *inode)
245 if (atomic_read(&inode->i_count) == 0) {
246 struct ll_inode_info *lli = ll_i2info(inode);
247 struct lov_stripe_md *md = lli->lli_smd;
248 char *symlink_name = lli->lli_symlink_name;
251 int size = sizeof(*md) +
252 md->lmd_stripe_count * sizeof(struct lov_oinfo);
257 OBD_FREE(symlink_name, strlen(symlink_name) + 1);
258 lli->lli_symlink_name = NULL;
263 static void ll_delete_inode(struct inode *inode)
265 if (S_ISREG(inode->i_mode)) {
268 struct lov_stripe_md *md = ll_i2info(inode)->lli_smd;
273 if (md->lmd_object_id == 0) {
274 CERROR("This really happens\n");
275 /* No obdo was ever created */
283 oa->o_id = md->lmd_object_id;
284 oa->o_easize = md->lmd_easize;
285 oa->o_mode = inode->i_mode;
286 oa->o_valid = OBD_MD_FLID | OBD_MD_FLEASIZE | OBD_MD_FLMODE;
288 err = obd_destroy(ll_i2obdconn(inode), oa, md);
290 CDEBUG(D_SUPER, "obd destroy of %Ld error %d\n",
291 md->lmd_object_id, err);
297 /* like inode_setattr, but doesn't mark the inode dirty */
298 static int ll_attr2inode(struct inode * inode, struct iattr * attr, int trunc)
300 unsigned int ia_valid = attr->ia_valid;
303 if ((ia_valid & ATTR_SIZE) && trunc) {
304 error = vmtruncate(inode, attr->ia_size);
307 } else if (ia_valid & ATTR_SIZE)
308 inode->i_size = attr->ia_size;
310 if (ia_valid & ATTR_UID)
311 inode->i_uid = attr->ia_uid;
312 if (ia_valid & ATTR_GID)
313 inode->i_gid = attr->ia_gid;
314 if (ia_valid & ATTR_ATIME)
315 inode->i_atime = attr->ia_atime;
316 if (ia_valid & ATTR_MTIME)
317 inode->i_mtime = attr->ia_mtime;
318 if (ia_valid & ATTR_CTIME)
319 inode->i_ctime = attr->ia_ctime;
320 if (ia_valid & ATTR_MODE) {
321 inode->i_mode = attr->ia_mode;
322 if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID))
323 inode->i_mode &= ~S_ISGID;
329 int ll_inode_setattr(struct inode *inode, struct iattr *attr, int do_trunc)
331 struct ptlrpc_request *request = NULL;
332 struct ll_sb_info *sbi = ll_i2sbi(inode);
337 /* change incore inode */
338 ll_attr2inode(inode, attr, do_trunc);
340 err = mdc_setattr(&sbi->ll_mdc_conn, inode, attr, &request);
342 CERROR("mdc_setattr fails (%d)\n", err);
344 ptlrpc_req_finished(request);
349 int ll_setattr(struct dentry *de, struct iattr *attr)
351 int rc = inode_change_ok(de->d_inode, attr);
356 return ll_inode_setattr(de->d_inode, attr, 1);
359 static int ll_statfs(struct super_block *sb, struct statfs *sfs)
361 struct ptlrpc_request *request = NULL;
362 struct ll_sb_info *sbi = ll_s2sbi(sb);
366 memset(sfs, 0, sizeof(*sfs));
367 rc = mdc_statfs(&sbi->ll_mdc_conn, sfs, &request);
368 ptlrpc_req_finished(request);
370 CERROR("obd_statfs fails: rc = %d\n", rc);
372 CDEBUG(D_SUPER, "statfs shows blocks %ld/%ld objects %ld/%ld\n",
373 sfs->f_bavail, sfs->f_blocks, sfs->f_ffree,sfs->f_files);
375 /* temporary until mds_statfs returns statfs info for all OSTs */
377 struct statfs obd_sfs;
379 rc = obd_statfs(&sbi->ll_osc_conn, &obd_sfs);
381 CERROR("obd_statfs fails: rc = %d\n", rc);
384 CDEBUG(D_SUPER, "obd_statfs returns blocks %ld/%ld, "
386 obd_sfs.f_bavail, obd_sfs.f_blocks,
387 obd_sfs.f_ffree, obd_sfs.f_files);
389 sfs->f_bfree = obd_sfs.f_bfree;
390 sfs->f_bavail = obd_sfs.f_bavail;
391 sfs->f_blocks = obd_sfs.f_blocks;
392 if (obd_sfs.f_ffree < sfs->f_ffree)
393 sfs->f_ffree = obd_sfs.f_ffree;
400 inline int ll_stripe_mds_md_size(struct super_block *sb)
402 struct client_obd *mdc = sbi2mdc(ll_s2sbi(sb));
403 return mdc->cl_max_mdsize;
406 static void ll_read_inode2(struct inode *inode, void *opaque)
408 struct ll_inode_md *md = opaque;
409 struct mds_body *body = md->body;
410 struct ll_inode_info *lli = ll_i2info(inode);
413 sema_init(&lli->lli_open_sem, 1);
415 /* core attributes first */
416 if (body->valid & OBD_MD_FLID)
417 inode->i_ino = body->ino;
418 if (body->valid & OBD_MD_FLATIME)
419 inode->i_atime = body->atime;
420 if (body->valid & OBD_MD_FLMTIME)
421 inode->i_mtime = body->mtime;
422 if (body->valid & OBD_MD_FLCTIME)
423 inode->i_ctime = body->ctime;
424 if (body->valid & OBD_MD_FLMODE)
425 inode->i_mode = body->mode;
426 if (body->valid & OBD_MD_FLUID)
427 inode->i_uid = body->uid;
428 if (body->valid & OBD_MD_FLGID)
429 inode->i_gid = body->gid;
430 if (body->valid & OBD_MD_FLFLAGS)
431 inode->i_flags = body->flags;
432 if (body->valid & OBD_MD_FLNLINK)
433 inode->i_nlink = body->nlink;
434 if (body->valid & OBD_MD_FLGENER)
435 inode->i_generation = body->generation;
436 if (body->valid & OBD_MD_FLRDEV)
437 inode->i_rdev = body->extra;
438 if (body->valid & OBD_MD_FLSIZE)
439 inode->i_size = body->size;
442 //if (body->valid & OBD_MD_FLEASIZE)
443 if (md && md->md && md->md->lmd_stripe_count) {
444 struct lov_mds_md *smd = md->md;
446 if (md->md->lmd_easize != ll_stripe_mds_md_size(inode->i_sb)) {
447 CERROR("Striping metadata size error %ld\n",
451 size = sizeof(*lli->lli_smd) +
452 md->md->lmd_stripe_count * sizeof(struct lov_oinfo);
453 OBD_ALLOC(lli->lli_smd, size);
455 CERROR("No memory for %d\n", size);
458 lov_unpackmd(lli->lli_smd, smd);
463 /* Get the authoritative file size */
464 if (lli->lli_smd && (inode->i_mode & S_IFREG)) {
467 rc = ll_file_size(inode, lli->lli_smd);
469 CERROR("ll_file_size: %d\n", rc);
470 /* FIXME: need to somehow prevent inode creation */
475 /* OIDEBUG(inode); */
477 if (S_ISREG(inode->i_mode)) {
478 inode->i_op = &ll_file_inode_operations;
479 inode->i_fop = &ll_file_operations;
480 inode->i_mapping->a_ops = &ll_aops;
482 } else if (S_ISDIR(inode->i_mode)) {
483 inode->i_op = &ll_dir_inode_operations;
484 inode->i_fop = &ll_dir_operations;
485 inode->i_mapping->a_ops = &ll_dir_aops;
487 } else if (S_ISLNK(inode->i_mode)) {
488 inode->i_op = &ll_fast_symlink_inode_operations;
491 init_special_inode(inode, inode->i_mode, inode->i_rdev);
498 /* exported operations */
499 struct super_operations ll_super_operations =
501 read_inode2: ll_read_inode2,
502 clear_inode: ll_clear_inode,
503 delete_inode: ll_delete_inode,
504 put_super: ll_put_super,
508 struct file_system_type lustre_lite_fs_type = {
509 "lustre_lite", 0, ll_read_super, NULL
512 static int __init init_lustre_lite(void)
514 printk(KERN_INFO "Lustre Lite 0.0.1, info@clusterfs.com\n");
515 ll_file_data_slab = kmem_cache_create("ll_file_data",
516 sizeof(struct ll_file_data), 0,
517 SLAB_HWCACHE_ALIGN, NULL, NULL);
518 if (ll_file_data_slab == NULL)
520 return register_filesystem(&lustre_lite_fs_type);
523 static void __exit exit_lustre_lite(void)
525 unregister_filesystem(&lustre_lite_fs_type);
526 kmem_cache_destroy(ll_file_data_slab);
529 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
530 MODULE_DESCRIPTION("Lustre Lite Client File System v1.0");
531 MODULE_LICENSE("GPL");
533 module_init(init_lustre_lite);
534 module_exit(exit_lustre_lite);