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/lustre_lite.h>
16 #include <linux/lustre_ha.h>
17 #include <linux/lustre_dlm.h>
19 kmem_cache_t *ll_file_data_slab;
20 extern struct address_space_operations ll_aops;
21 extern struct address_space_operations ll_dir_aops;
22 struct super_operations ll_super_operations;
24 extern int ll_recover(struct ptlrpc_client *);
25 extern int ll_commitcbd_setup(struct ll_sb_info *);
26 extern int ll_commitcbd_cleanup(struct ll_sb_info *);
28 static char *ll_read_opt(const char *opt, char *data)
34 CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
35 if ( strncmp(opt, data, strlen(opt)) )
37 if ( (value = strchr(data, '=')) == NULL )
41 OBD_ALLOC(retval, strlen(value) + 1);
43 CERROR("out of memory!\n");
47 memcpy(retval, value, strlen(value)+1);
48 CDEBUG(D_SUPER, "Assigned option: %s, value %s\n", opt, retval);
52 static void ll_options(char *options, char **ost, char **mds)
62 for (this_char = strtok (options, ",");
64 this_char = strtok (NULL, ",")) {
65 CDEBUG(D_SUPER, "this_char %s\n", this_char);
66 if ( (!*ost && (*ost = ll_read_opt("ost", this_char)))||
67 (!*mds && (*mds = ll_read_opt("mds", this_char))) )
74 #define log2(n) ffz(~(n))
77 static struct super_block * ll_read_super(struct super_block *sb,
78 void *data, int silent)
80 struct inode *root = 0;
81 struct obd_device *obd;
82 struct ll_sb_info *sbi;
86 struct ll_fid rootfid;
88 __u64 last_committed, last_rcvd;
90 struct ptlrpc_request *request = NULL;
91 struct ll_inode_md md;
96 OBD_ALLOC(sbi, sizeof(*sbi));
102 sb->u.generic_sbp = sbi;
104 ll_options(data, &ost, &mds);
108 GOTO(out_free, sb = NULL);
113 GOTO(out_free, sb = NULL);
116 obd = class_uuid2obd(mds);
118 CERROR("MDS %s: not setup or attached\n", mds);
119 GOTO(out_free, sb = NULL);
122 /* First the MDS since an LOV requires an the MDC connection
123 to find its descriptor */
125 err = connmgr_connect(ptlrpc_connmgr, sbi->ll_mds_conn);
127 CERROR("cannot connect to MDS: rc = %d\n", err);
128 GOTO(out_rpc, sb = NULL);
132 err = obd_connect(&sbi->ll_mdc_conn, obd);
134 CERROR("cannot connect to %s: rc = %d\n", mds, err);
135 GOTO(out_free, sb = NULL);
137 sbi2mdc(sbi)->mdc_conn->c_level = LUSTRE_CONN_FULL;
139 /* now the OST, which could be an LOV */
141 obd = class_uuid2obd(ost);
143 CERROR("OST %s: not setup or attached\n", ost);
144 GOTO(out_free, sb = NULL);
146 err = obd_connect(&sbi->ll_osc_conn, obd);
148 CERROR("cannot connect to %s: rc = %d\n", ost, err);
149 GOTO(out_free, sb = NULL);
152 /* XXX: need to store the last_* values somewhere */
153 err = mdc_getstatus(&sbi->ll_mdc_conn,
154 &rootfid, &last_committed,
155 &last_rcvd, &last_xid,
158 CERROR("cannot mds_connect: rc = %d\n", err);
159 GOTO(out_disc, 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));
165 err = mdc_statfs(&sbi->ll_mdc_conn, &sfs, &request);
166 sb->s_blocksize = sfs.f_bsize;
167 sb->s_blocksize_bits = log2(sfs.f_bsize);
168 sb->s_magic = LL_SUPER_MAGIC;
169 sb->s_maxbytes = (1ULL << (32 + 9)) - sfs.f_bsize;
170 ptlrpc_req_finished(request);
172 sb->s_op = &ll_super_operations;
174 /* make root inode */
175 err = mdc_getattr(&sbi->ll_mdc_conn,
176 sbi->ll_rootino, S_IFDIR, OBD_MD_FLNOTOBD|OBD_MD_FLBLOCKS, 0, &request);
178 CERROR("mdc_getattr failed for root: rc = %d\n", err);
179 GOTO(out_mdc, sb = NULL);
182 /* initialize committed transaction callback daemon */
183 spin_lock_init(&sbi->ll_commitcbd_lock);
184 init_waitqueue_head(&sbi->ll_commitcbd_waitq);
185 init_waitqueue_head(&sbi->ll_commitcbd_ctl_waitq);
186 sbi->ll_commitcbd_flags = 0;
187 err = ll_commitcbd_setup(sbi);
189 CERROR("failed to start commit callback daemon: rc = %d\n",err);
190 GOTO(out_mdc, sb = NULL);
193 md.body = lustre_msg_buf(request->rq_repmsg, 0);
195 root = iget4(sb, sbi->ll_rootino, NULL, &md);
198 sb->s_root = d_alloc_root(root);
200 CERROR("lustre_lite: bad iget4 for root\n");
201 GOTO(out_cdb, sb = NULL);
204 ptlrpc_free_req(request);
208 OBD_FREE(mds, strlen(mds) + 1);
210 OBD_FREE(ost, strlen(ost) + 1);
215 ll_commitcbd_cleanup(sbi);
217 obd_disconnect(&sbi->ll_mdc_conn);
218 obd_disconnect(&sbi->ll_osc_conn);
220 ptlrpc_free_req(request);
221 obd_disconnect(&sbi->ll_osc_conn);
223 OBD_FREE(sbi, sizeof(*sbi));
227 } /* ll_read_super */
229 static void ll_put_super(struct super_block *sb)
231 struct ll_sb_info *sbi = ll_s2sbi(sb);
233 ll_commitcbd_cleanup(sbi);
234 obd_disconnect(&sbi->ll_osc_conn);
235 obd_disconnect(&sbi->ll_mdc_conn);
236 OBD_FREE(sbi, sizeof(*sbi));
242 static void ll_clear_inode(struct inode *inode)
244 if (atomic_read(&inode->i_count) == 0) {
245 struct lov_stripe_md *md = ll_i2info(inode)->lli_smd;
247 OBD_FREE(md, md->lmd_size);
248 ll_i2info(inode)->lli_smd = NULL;
250 if (ll_i2info(inode)->lli_symlink_name) {
251 OBD_FREE(ll_i2info(inode)->lli_symlink_name,
252 strlen(ll_i2info(inode)->lli_symlink_name)+ 1);
253 ll_i2info(inode)->lli_symlink_name = NULL;
258 static void ll_delete_inode(struct inode *inode)
260 if (S_ISREG(inode->i_mode)) {
263 struct lov_stripe_md *md = ll_i2info(inode)->lli_smd;
268 oa.o_id = md->lmd_object_id;
269 oa.o_easize = md->lmd_size;
271 CERROR("This really happens\n");
272 /* No obdo was ever created */
276 err = obd_destroy(ll_i2obdconn(inode), &oa, md);
277 CDEBUG(D_SUPER, "obd destroy of %Ld error %d\n",
278 md->lmd_object_id, err);
284 /* like inode_setattr, but doesn't mark the inode dirty */
285 static int ll_attr2inode(struct inode * inode, struct iattr * attr, int trunc)
287 unsigned int ia_valid = attr->ia_valid;
290 if ((ia_valid & ATTR_SIZE) && trunc) {
291 error = vmtruncate(inode, attr->ia_size);
294 } else if (ia_valid & ATTR_SIZE)
295 inode->i_size = attr->ia_size;
297 if (ia_valid & ATTR_UID)
298 inode->i_uid = attr->ia_uid;
299 if (ia_valid & ATTR_GID)
300 inode->i_gid = attr->ia_gid;
301 if (ia_valid & ATTR_ATIME)
302 inode->i_atime = attr->ia_atime;
303 if (ia_valid & ATTR_MTIME)
304 inode->i_mtime = attr->ia_mtime;
305 if (ia_valid & ATTR_CTIME)
306 inode->i_ctime = attr->ia_ctime;
307 if (ia_valid & ATTR_MODE) {
308 inode->i_mode = attr->ia_mode;
309 if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID))
310 inode->i_mode &= ~S_ISGID;
316 int ll_inode_setattr(struct inode *inode, struct iattr *attr, int do_trunc)
318 struct ptlrpc_request *request = NULL;
319 struct ll_sb_info *sbi = ll_i2sbi(inode);
324 /* change incore inode */
325 ll_attr2inode(inode, attr, do_trunc);
327 err = mdc_setattr(&sbi->ll_mdc_conn, inode, attr, &request);
329 CERROR("mdc_setattr fails (%d)\n", err);
331 ptlrpc_req_finished(request);
336 int ll_setattr(struct dentry *de, struct iattr *attr)
338 int rc = inode_change_ok(de->d_inode, attr);
343 return ll_inode_setattr(de->d_inode, attr, 1);
346 static int ll_statfs(struct super_block *sb, struct statfs *sfs)
348 struct ptlrpc_request *request = NULL;
349 struct ll_sb_info *sbi = ll_s2sbi(sb);
353 memset(sfs, 0, sizeof(*sfs));
354 rc = mdc_statfs(&sbi->ll_mdc_conn, sfs, &request);
355 ptlrpc_req_finished(request);
357 CERROR("obd_statfs fails: rc = %d\n", rc);
359 CDEBUG(D_SUPER, "statfs shows blocks %ld/%ld objects %ld/%ld\n",
360 sfs->f_bavail, sfs->f_blocks, sfs->f_files,sfs->f_ffree);
362 /* temporary until mds_statfs returns statfs info for all OSTs */
364 struct statfs obd_sfs;
366 rc = obd_statfs(&sbi->ll_osc_conn, &obd_sfs);
368 CERROR("obd_statfs fails: rc = %d\n", rc);
371 CDEBUG(D_SUPER, "obd_statfs returns blocks %ld/%ld, "
373 obd_sfs.f_bavail, obd_sfs.f_blocks,
374 obd_sfs.f_ffree, obd_sfs.f_files);
376 sfs->f_bfree = obd_sfs.f_bfree;
377 sfs->f_bavail = obd_sfs.f_bavail;
378 sfs->f_blocks = obd_sfs.f_blocks;
379 if (obd_sfs.f_ffree < sfs->f_ffree)
380 sfs->f_ffree = obd_sfs.f_ffree;
387 inline int ll_stripe_md_size(struct super_block *sb)
389 struct mdc_obd *mdc = sbi2mdc(ll_s2sbi(sb));
390 return mdc->mdc_max_mdsize;
393 static void ll_to_inode(struct inode *dst, struct ll_inode_md *md)
395 struct mds_body *body = md->body;
396 struct ll_inode_info *ii = ll_i2info(dst);
398 /* core attributes first */
399 if (body->valid & OBD_MD_FLID)
400 dst->i_ino = body->ino;
401 if (body->valid & OBD_MD_FLATIME)
402 dst->i_atime = body->atime;
403 if (body->valid & OBD_MD_FLMTIME)
404 dst->i_mtime = body->mtime;
405 if (body->valid & OBD_MD_FLCTIME)
406 dst->i_ctime = body->ctime;
407 if (body->valid & OBD_MD_FLSIZE)
408 dst->i_size = body->size;
409 if (body->valid & OBD_MD_FLMODE)
410 dst->i_mode = body->mode;
411 if (body->valid & OBD_MD_FLUID)
412 dst->i_uid = body->uid;
413 if (body->valid & OBD_MD_FLGID)
414 dst->i_gid = body->gid;
415 if (body->valid & OBD_MD_FLFLAGS)
416 dst->i_flags = body->flags;
417 if (body->valid & OBD_MD_FLNLINK)
418 dst->i_nlink = body->nlink;
419 if (body->valid & OBD_MD_FLGENER)
420 dst->i_generation = body->generation;
421 if (body->valid & OBD_MD_FLRDEV)
422 dst->i_rdev = body->extra;
423 if (md && md->md && md->md->lmd_stripe_count) {
424 struct lov_stripe_md *smd = md->md;
425 int size = ll_stripe_md_size(dst->i_sb);
426 if (md->md->lmd_size != size) {
427 CERROR("Striping metadata size error %ld\n",
431 OBD_ALLOC(ii->lli_smd, size);
433 CERROR("No memory for %d\n", size);
436 memcpy(ii->lli_smd, smd, size);
440 static void ll_read_inode2(struct inode *inode, void *opaque)
442 struct ll_inode_md *md = opaque;
445 ll_to_inode(inode, md);
447 /* OIDEBUG(inode); */
449 if (S_ISREG(inode->i_mode)) {
450 inode->i_op = &ll_file_inode_operations;
451 inode->i_fop = &ll_file_operations;
452 inode->i_mapping->a_ops = &ll_aops;
454 } else if (S_ISDIR(inode->i_mode)) {
455 inode->i_op = &ll_dir_inode_operations;
456 inode->i_fop = &ll_dir_operations;
457 inode->i_mapping->a_ops = &ll_dir_aops;
459 } else if (S_ISLNK(inode->i_mode)) {
460 inode->i_op = &ll_fast_symlink_inode_operations;
463 init_special_inode(inode, inode->i_mode,
464 ((int *)ll_i2info(inode)->lli_inline)[0]);
471 /* exported operations */
472 struct super_operations ll_super_operations =
474 read_inode2: ll_read_inode2,
475 clear_inode: ll_clear_inode,
476 delete_inode: ll_delete_inode,
477 put_super: ll_put_super,
481 struct file_system_type lustre_lite_fs_type = {
482 "lustre_lite", 0, ll_read_super, NULL
485 static int __init init_lustre_lite(void)
487 printk(KERN_INFO "Lustre Lite 0.0.1, info@clusterfs.com\n");
488 ll_file_data_slab = kmem_cache_create("ll_file_data",
489 sizeof(struct ll_file_data), 0,
490 SLAB_HWCACHE_ALIGN, NULL, NULL);
491 if (ll_file_data_slab == NULL)
493 return register_filesystem(&lustre_lite_fs_type);
496 static void __exit exit_lustre_lite(void)
498 unregister_filesystem(&lustre_lite_fs_type);
499 kmem_cache_destroy(ll_file_data_slab);
502 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
503 MODULE_DESCRIPTION("Lustre Lite Client File System v1.0");
504 MODULE_LICENSE("GPL");
506 module_init(init_lustre_lite);
507 module_exit(exit_lustre_lite);