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) 1996 Peter J. Braam <braam@stelias.com>
10 * Copryright (C) 1999 Stelias Computing Inc. <braam@stelias.com>
11 * Copryright (C) 1999 Seagate Technology Inc.
12 * Copryright (C) 2001 Mountain View Data, Inc.
13 * Copryright (C) 2002 Cluster File Systems, Inc.
17 #define DEBUG_SUBSYSTEM S_LLITE
19 #include <linux/module.h>
20 #include <linux/lustre_lite.h>
21 #include <linux/lustre_ha.h>
22 #include <linux/lustre_dlm.h>
24 kmem_cache_t *ll_file_data_slab;
25 extern struct address_space_operations ll_aops;
26 extern struct address_space_operations ll_dir_aops;
27 struct super_operations ll_super_operations;
29 extern int ll_recover(struct ptlrpc_client *);
30 extern int ll_commitcbd_setup(struct ll_sb_info *);
31 extern int ll_commitcbd_cleanup(struct ll_sb_info *);
33 static char *ll_read_opt(const char *opt, char *data)
39 CDEBUG(D_INFO, "option: %s, data %s\n", opt, data);
40 if ( strncmp(opt, data, strlen(opt)) )
42 if ( (value = strchr(data, '=')) == NULL )
46 OBD_ALLOC(retval, strlen(value) + 1);
48 CERROR("out of memory!\n");
52 memcpy(retval, value, strlen(value)+1);
53 CDEBUG(D_SUPER, "Assigned option: %s, value %s\n", opt, retval);
57 static void ll_options(char *options, char **ost, char **mds)
67 for (this_char = strtok (options, ",");
69 this_char = strtok (NULL, ",")) {
70 CDEBUG(D_INFO, "this_char %s\n", this_char);
71 if ( (!*ost && (*ost = ll_read_opt("ost", this_char)))||
72 (!*mds && (*mds = ll_read_opt("mds", this_char))) )
78 static struct super_block * ll_read_super(struct super_block *sb,
79 void *data, int silent)
81 struct inode *root = 0;
82 struct ll_sb_info *sbi;
87 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 devno = simple_strtoul(ost, NULL, 0);
117 if (devno >= MAX_OBD_DEVICES) {
118 CERROR("devno of %s too high\n", ost);
119 GOTO(out_free, sb = NULL);
122 sbi->ll_osc_conn.oc_dev = &obd_dev[devno];
123 err = obd_connect(&sbi->ll_osc_conn);
125 CERROR("cannot connect to %s: rc = %d\n", ost, err);
126 GOTO(out_free, sb = NULL);
129 devno = simple_strtoul(mds, NULL, 0);
130 if (devno >= MAX_OBD_DEVICES) {
131 CERROR("devno of %s too high\n", mds);
132 GOTO(out_free, sb = NULL);
135 sbi->ll_mdc_conn.oc_dev = &obd_dev[devno];
136 err = obd_connect(&sbi->ll_mdc_conn);
138 CERROR("cannot connect to %s: rc = %d\n", mds, err);
139 GOTO(out_free, sb = NULL);
143 err = connmgr_connect(ptlrpc_connmgr, sbi->ll_mds_conn);
145 CERROR("cannot connect to MDS: rc = %d\n", err);
146 GOTO(out_rpc, sb = NULL);
150 sbi2mdc(sbi)->mdc_conn->c_level = LUSTRE_CONN_FULL;
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)rootfid.id);
162 sbi->ll_rootino = rootfid.id;
164 sb->s_maxbytes = 1ULL << 36;
165 /* XXX get this with a get_info call (like we have in OBDFS),
166 this info call should return the blocksize of the MDS */
167 sb->s_blocksize = 4096;
168 sb->s_blocksize_bits = 12;
169 sb->s_magic = LL_SUPER_MAGIC;
170 sb->s_op = &ll_super_operations;
172 /* make root inode */
173 err = mdc_getattr(&sbi->ll_mdc_conn,
174 sbi->ll_rootino, S_IFDIR,
175 OBD_MD_FLNOTOBD|OBD_MD_FLBLOCKS, 0, &request);
177 CERROR("mdc_getattr failed for root: rc = %d\n", err);
178 GOTO(out_mdc, sb = NULL);
181 /* initialize committed transaction callback daemon */
182 spin_lock_init(&sbi->ll_commitcbd_lock);
183 init_waitqueue_head(&sbi->ll_commitcbd_waitq);
184 init_waitqueue_head(&sbi->ll_commitcbd_ctl_waitq);
185 sbi->ll_commitcbd_flags = 0;
186 err = ll_commitcbd_setup(sbi);
188 CERROR("failed to start commit callback daemon: rc = %d\n",err);
189 GOTO(out_mdc, sb = NULL);
192 md.body = lustre_msg_buf(request->rq_repmsg, 0);
194 root = iget4(sb, sbi->ll_rootino, NULL, &md);
197 sb->s_root = d_alloc_root(root);
199 CERROR("lustre_lite: bad iget4 for root\n");
200 GOTO(out_cdb, sb = NULL);
203 ptlrpc_free_req(request);
207 OBD_FREE(mds, strlen(mds) + 1);
209 OBD_FREE(ost, strlen(ost) + 1);
214 ll_commitcbd_cleanup(sbi);
216 obd_disconnect(&sbi->ll_mdc_conn);
217 obd_disconnect(&sbi->ll_osc_conn);
219 ptlrpc_free_req(request);
220 obd_disconnect(&sbi->ll_osc_conn);
222 OBD_FREE(sbi, sizeof(*sbi));
226 } /* ll_read_super */
228 static void ll_put_super(struct super_block *sb)
230 struct ll_sb_info *sbi = ll_s2sbi(sb);
232 ll_commitcbd_cleanup(sbi);
233 obd_disconnect(&sbi->ll_osc_conn);
234 obd_disconnect(&sbi->ll_mdc_conn);
235 OBD_FREE(sbi, sizeof(*sbi));
241 static void ll_clear_inode(struct inode *inode)
243 if (atomic_read(&inode->i_count) == 0) {
244 struct obdo *oa = ll_i2info(inode)->lli_obdo;
247 ll_i2info(inode)->lli_obdo = NULL;
249 if (ll_i2info(inode)->lli_symlink_name) {
250 OBD_FREE(ll_i2info(inode)->lli_symlink_name,
251 strlen(ll_i2info(inode)->lli_symlink_name)+ 1);
252 ll_i2info(inode)->lli_symlink_name = NULL;
257 static void ll_delete_inode(struct inode *inode)
259 if (S_ISREG(inode->i_mode)) {
262 oa = ll_i2info(inode)->lli_obdo;
265 CERROR("no memory\n");
269 err = obd_destroy(ll_i2obdconn(inode), oa);
270 CDEBUG(D_INODE, "obd destroy of %Ld error %d\n",
271 (unsigned long long)oa->o_id, err);
278 /* like inode_setattr, but doesn't mark the inode dirty */
279 static int ll_attr2inode(struct inode * inode, struct iattr * attr, int trunc)
281 unsigned int ia_valid = attr->ia_valid;
284 if ((ia_valid & ATTR_SIZE) && trunc ) {
285 error = vmtruncate(inode, attr->ia_size);
288 } else if (ia_valid & ATTR_SIZE) {
289 inode->i_size = attr->ia_size;
292 if (ia_valid & ATTR_UID)
293 inode->i_uid = attr->ia_uid;
294 if (ia_valid & ATTR_GID)
295 inode->i_gid = attr->ia_gid;
296 if (ia_valid & ATTR_ATIME)
297 inode->i_atime = attr->ia_atime;
298 if (ia_valid & ATTR_MTIME)
299 inode->i_mtime = attr->ia_mtime;
300 if (ia_valid & ATTR_CTIME)
301 inode->i_ctime = attr->ia_ctime;
302 if (ia_valid & ATTR_MODE) {
303 inode->i_mode = attr->ia_mode;
304 if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID))
305 inode->i_mode &= ~S_ISGID;
311 int ll_inode_setattr(struct inode *inode, struct iattr *attr, int do_trunc)
313 struct ptlrpc_request *request = NULL;
314 struct ll_sb_info *sbi = ll_i2sbi(inode);
319 /* change incore inode */
320 ll_attr2inode(inode, attr, do_trunc);
322 err = mdc_setattr(&sbi->ll_mdc_conn, inode, attr,
325 CERROR("mdc_setattr fails (%d)\n", err);
327 ptlrpc_req_finished(request);
332 int ll_setattr(struct dentry *de, struct iattr *attr)
334 return ll_inode_setattr(de->d_inode, attr, 1);
337 static int ll_statfs(struct super_block *sb, struct statfs *buf)
343 err = obd_statfs(&ll_s2sbi(sb)->ll_osc_conn, &tmp);
345 CERROR("obd_statfs fails (%d)\n", err);
348 memcpy(buf, &tmp, sizeof(*buf));
350 err = mdc_statfs(&sbi->ll_mds_client, sbi->ll_mds_conn, &tmp,
353 CERROR("obd_statfs fails (%d)\n", err);
356 if (tmp.f_files < buf->f_files)
357 buf->f_files = tmp.f_files;
358 if (tmp.f_ffree < buf->f_ffree)
359 buf->f_ffree = tmp.f_ffree;
360 buf->f_namelen = tmp.f_namelen;
362 CDEBUG(D_SUPER, "statfs returns avail %ld\n", tmp.f_bavail);
367 static void inline ll_to_inode(struct inode *dst, struct ll_inode_md *md)
369 struct mds_body *body = md->body;
370 struct ll_inode_info *ii = ll_i2info(dst);
372 /* core attributes first */
373 if ( body->valid & OBD_MD_FLID )
374 dst->i_ino = body->ino;
375 if ( body->valid & OBD_MD_FLATIME )
376 dst->i_atime = body->atime;
377 if ( body->valid & OBD_MD_FLMTIME )
378 dst->i_mtime = body->mtime;
379 if ( body->valid & OBD_MD_FLCTIME )
380 dst->i_ctime = body->ctime;
381 if ( body->valid & OBD_MD_FLSIZE )
382 dst->i_size = body->size;
383 if ( body->valid & OBD_MD_FLMODE )
384 dst->i_mode = body->mode;
385 if ( body->valid & OBD_MD_FLUID )
386 dst->i_uid = body->uid;
387 if ( body->valid & OBD_MD_FLGID )
388 dst->i_gid = body->gid;
389 if ( body->valid & OBD_MD_FLFLAGS )
390 dst->i_flags = body->flags;
391 if ( body->valid & OBD_MD_FLNLINK )
392 dst->i_nlink = body->nlink;
393 if ( body->valid & OBD_MD_FLGENER )
394 dst->i_generation = body->generation;
396 /* this will become more elaborate for striping etc */
397 if (md->obdo != NULL && md->obdo->o_valid != 0) {
398 ii->lli_obdo = obdo_alloc();
399 memcpy(ii->lli_obdo, md->obdo, sizeof(*md->obdo));
403 if (obdo_has_inline(oa)) {
404 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) ||
405 S_ISFIFO(inode->i_mode)) {
406 obd_rdev rdev = *((obd_rdev *)oa->o_inline);
408 "copying device %x from obdo to inode\n", rdev);
409 init_special_inode(inode, inode->i_mode, rdev);
411 CDEBUG(D_INFO, "copying inline from obdo to inode\n");
412 memcpy(oinfo->lli_inline, oa->o_inline, OBD_INLINESZ);
414 oinfo->lli_flags |= OBD_FL_INLINEDATA;
419 static inline void ll_read_inode2(struct inode *inode, void *opaque)
421 struct ll_inode_md *md = opaque;
424 ll_to_inode(inode, md);
426 /* OIDEBUG(inode); */
428 if (S_ISREG(inode->i_mode)) {
429 inode->i_op = &ll_file_inode_operations;
430 inode->i_fop = &ll_file_operations;
431 inode->i_mapping->a_ops = &ll_aops;
433 } else if (S_ISDIR(inode->i_mode)) {
434 inode->i_op = &ll_dir_inode_operations;
435 inode->i_fop = &ll_dir_operations;
436 inode->i_mapping->a_ops = &ll_dir_aops;
438 } else if (S_ISLNK(inode->i_mode)) {
439 inode->i_op = &ll_fast_symlink_inode_operations;
442 init_special_inode(inode, inode->i_mode,
443 ((int *)ll_i2info(inode)->lli_inline)[0]);
450 /* exported operations */
451 struct super_operations ll_super_operations =
453 read_inode2: ll_read_inode2,
454 clear_inode: ll_clear_inode,
455 delete_inode: ll_delete_inode,
456 put_super: ll_put_super,
460 struct file_system_type lustre_lite_fs_type = {
461 "lustre_lite", 0, ll_read_super, NULL
464 static int __init init_lustre_lite(void)
466 printk(KERN_INFO "Lustre Lite 0.0.1, braam@clusterfs.com\n");
467 ll_file_data_slab = kmem_cache_create("ll_file_data",
468 sizeof(struct ll_file_data), 0,
469 SLAB_HWCACHE_ALIGN, NULL, NULL);
470 if (ll_file_data_slab == NULL)
472 return register_filesystem(&lustre_lite_fs_type);
475 static void __exit exit_lustre_lite(void)
477 unregister_filesystem(&lustre_lite_fs_type);
478 kmem_cache_destroy(ll_file_data_slab);
481 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
482 MODULE_DESCRIPTION("Lustre Lite Client File System v1.0");
483 MODULE_LICENSE("GPL");
485 module_init(init_lustre_lite);
486 module_exit(exit_lustre_lite);