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 **dev, char **vers)
67 for (this_char = strtok (options, ",");
69 this_char = strtok (NULL, ",")) {
70 CDEBUG(D_INFO, "this_char %s\n", this_char);
71 if ( (!*dev && (*dev = ll_read_opt("device", this_char)))||
72 (!*vers && (*vers = ll_read_opt("version", 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;
95 OBD_ALLOC(sbi, sizeof(*sbi));
101 sb->u.generic_sbp = sbi;
103 ll_options(data, &device, &version);
106 CERROR("no device\n");
107 GOTO(out_free, sb = NULL);
110 devno = simple_strtoul(device, NULL, 0);
111 if (devno >= MAX_OBD_DEVICES) {
112 CERROR("device of %s too high\n", device);
113 GOTO(out_free, sb = NULL);
116 sbi->ll_conn.oc_dev = &obd_dev[devno];
117 err = obd_connect(&sbi->ll_conn);
119 CERROR("cannot connect to %s: rc = %d\n", device, err);
120 GOTO(out_free, sb = NULL);
123 sbi->ll_namespace = ldlm_namespace_new(NULL, 1);
124 if (sbi->ll_namespace == NULL) {
125 CERROR("failed to create local lock namespace\n");
126 GOTO(out_free, sb = NULL);
129 ptlrpc_init_client(ptlrpc_connmgr, ll_recover,
130 MDS_REQUEST_PORTAL, MDC_REPLY_PORTAL,
131 &sbi->ll_mds_client);
133 sbi->ll_mds_client.cli_data = sbi;
134 sbi->ll_mds_client.cli_name = "mdc";
135 sbi->ll_mds_conn = ptlrpc_uuid_to_connection("mds");
136 if (!sbi->ll_mds_conn) {
137 CERROR("cannot find MDS\n");
138 GOTO(out_disc, sb = NULL);
141 err = connmgr_connect(ptlrpc_connmgr, sbi->ll_mds_conn);
143 CERROR("cannot connect to MDS: rc = %d\n", err);
144 ptlrpc_put_connection(sbi->ll_mds_conn);
145 GOTO(out_disc, sb = NULL);
148 sbi->ll_mds_conn->c_level = LUSTRE_CONN_FULL;
150 /* XXX: need to store the last_* values somewhere */
151 err = mdc_connect(&sbi->ll_mds_client, sbi->ll_mds_conn,
152 &rootfid, &last_committed, &last_rcvd, &last_xid,
155 CERROR("cannot mds_connect: rc = %d\n", err);
156 GOTO(out_disc, sb = NULL);
158 CERROR("rootfid %ld\n", (unsigned long)rootfid.id);
159 sbi->ll_rootino = rootfid.id;
161 sb->s_maxbytes = 1ULL << 36;
162 sb->s_blocksize = PAGE_SIZE;
163 sb->s_blocksize_bits = (unsigned char)PAGE_SHIFT;
164 sb->s_magic = LL_SUPER_MAGIC;
165 sb->s_op = &ll_super_operations;
167 /* make root inode */
168 err = mdc_getattr(&sbi->ll_mds_client, sbi->ll_mds_conn,
169 sbi->ll_rootino, S_IFDIR,
170 OBD_MD_FLNOTOBD|OBD_MD_FLBLOCKS, 0, &request);
172 CERROR("mdc_getattr failed for root: rc = %d\n", err);
173 GOTO(out_req, sb = NULL);
176 /* initialize committed transaction callback daemon */
177 spin_lock_init(&sbi->ll_commitcbd_lock);
178 init_waitqueue_head(&sbi->ll_commitcbd_waitq);
179 init_waitqueue_head(&sbi->ll_commitcbd_ctl_waitq);
180 sbi->ll_commitcbd_flags = 0;
181 err = ll_commitcbd_setup(sbi);
183 CERROR("failed to start commit callback daemon: rc = %d\n",err);
184 GOTO(out_req, sb = NULL);
187 root = iget4(sb, sbi->ll_rootino, NULL,
188 lustre_msg_buf(request->rq_repmsg, 0));
190 sb->s_root = d_alloc_root(root);
192 CERROR("lustre_lite: bad iget4 for root\n");
193 GOTO(out_req, sb = NULL);
197 ptlrpc_free_req(request);
200 obd_disconnect(&sbi->ll_conn);
203 if (sbi->ll_namespace)
204 ldlm_namespace_free(sbi->ll_namespace);
205 OBD_FREE(sbi, sizeof(*sbi));
208 OBD_FREE(device, strlen(device) + 1);
210 OBD_FREE(version, strlen(version) + 1);
213 } /* ll_read_super */
215 static void ll_put_super(struct super_block *sb)
217 struct ll_sb_info *sbi = sb->u.generic_sbp;
219 ll_commitcbd_cleanup(sbi);
220 obd_disconnect(&sbi->ll_conn);
221 ldlm_namespace_free(sbi->ll_namespace);
222 ptlrpc_put_connection(sbi->ll_mds_conn);
223 ptlrpc_cleanup_client(&sbi->ll_mds_client);
224 OBD_FREE(sb->u.generic_sbp, sizeof(*sbi));
230 extern inline struct obdo * ll_oa_from_inode(struct inode *inode, int valid);
231 static void ll_delete_inode(struct inode *inode)
233 if (S_ISREG(inode->i_mode)) {
236 oa = ll_oa_from_inode(inode, OBD_MD_FLNOTOBD);
238 CERROR("no memory\n");
241 err = obd_destroy(ll_i2obdconn(inode), oa);
242 CDEBUG(D_INODE, "obd destroy of %Ld error %d\n",
243 (unsigned long long)oa->o_id, err);
250 /* like inode_setattr, but doesn't mark the inode dirty */
251 static int ll_attr2inode(struct inode * inode, struct iattr * attr, int trunc)
253 unsigned int ia_valid = attr->ia_valid;
256 if ((ia_valid & ATTR_SIZE) && trunc ) {
257 error = vmtruncate(inode, attr->ia_size);
260 } else if (ia_valid & ATTR_SIZE) {
261 inode->i_size = attr->ia_size;
264 if (ia_valid & ATTR_UID)
265 inode->i_uid = attr->ia_uid;
266 if (ia_valid & ATTR_GID)
267 inode->i_gid = attr->ia_gid;
268 if (ia_valid & ATTR_ATIME)
269 inode->i_atime = attr->ia_atime;
270 if (ia_valid & ATTR_MTIME)
271 inode->i_mtime = attr->ia_mtime;
272 if (ia_valid & ATTR_CTIME)
273 inode->i_ctime = attr->ia_ctime;
274 if (ia_valid & ATTR_MODE) {
275 inode->i_mode = attr->ia_mode;
276 if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID))
277 inode->i_mode &= ~S_ISGID;
283 int ll_inode_setattr(struct inode *inode, struct iattr *attr, int do_trunc)
285 struct ptlrpc_request *request = NULL;
286 struct ll_sb_info *sbi = ll_i2sbi(inode);
291 /* change incore inode */
292 ll_attr2inode(inode, attr, do_trunc);
294 err = mdc_setattr(&sbi->ll_mds_client, sbi->ll_mds_conn, inode, attr,
297 CERROR("mdc_setattr fails (%d)\n", err);
299 ptlrpc_req_finished(request);
304 int ll_setattr(struct dentry *de, struct iattr *attr)
306 return ll_inode_setattr(de->d_inode, attr, 1);
309 static int ll_statfs(struct super_block *sb, struct statfs *buf)
315 err = obd_statfs(&ll_s2sbi(sb)->ll_conn, &tmp);
317 CERROR("obd_statfs fails (%d)\n", err);
320 memcpy(buf, &tmp, sizeof(*buf));
321 CDEBUG(D_SUPER, "statfs returns avail %ld\n", tmp.f_bavail);
326 static void inline ll_to_inode(struct inode *dst, struct mds_body *body)
328 struct ll_inode_info *ii =
329 (struct ll_inode_info *) &dst->u.generic_ip;
331 /* core attributes first */
332 if ( body->valid & OBD_MD_FLID )
333 dst->i_ino = body->ino;
334 if ( body->valid & OBD_MD_FLATIME )
335 dst->i_atime = body->atime;
336 if ( body->valid & OBD_MD_FLMTIME )
337 dst->i_mtime = body->mtime;
338 if ( body->valid & OBD_MD_FLCTIME )
339 dst->i_ctime = body->ctime;
340 if ( body->valid & OBD_MD_FLSIZE )
341 dst->i_size = body->size;
342 if ( body->valid & OBD_MD_FLMODE )
343 dst->i_mode = body->mode;
344 if ( body->valid & OBD_MD_FLUID )
345 dst->i_uid = body->uid;
346 if ( body->valid & OBD_MD_FLGID )
347 dst->i_gid = body->gid;
348 if ( body->valid & OBD_MD_FLFLAGS )
349 dst->i_flags = body->flags;
350 if ( body->valid & OBD_MD_FLNLINK )
351 dst->i_nlink = body->nlink;
352 if ( body->valid & OBD_MD_FLGENER )
353 dst->i_generation = body->generation;
355 /* this will become more elaborate for striping etc */
356 if (body->valid & OBD_MD_FLOBJID)
357 ii->lli_objid = body->objid;
360 if (obdo_has_inline(oa)) {
361 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) ||
362 S_ISFIFO(inode->i_mode)) {
363 obd_rdev rdev = *((obd_rdev *)oa->o_inline);
365 "copying device %x from obdo to inode\n", rdev);
366 init_special_inode(inode, inode->i_mode, rdev);
368 CDEBUG(D_INFO, "copying inline from obdo to inode\n");
369 memcpy(oinfo->lli_inline, oa->o_inline, OBD_INLINESZ);
371 oinfo->lli_flags |= OBD_FL_INLINEDATA;
376 static inline void ll_read_inode2(struct inode *inode, void *opaque)
378 struct mds_body *body = opaque;
381 ll_to_inode(inode, body);
383 /* OIDEBUG(inode); */
385 if (S_ISREG(inode->i_mode)) {
386 inode->i_op = &ll_file_inode_operations;
387 inode->i_fop = &ll_file_operations;
388 inode->i_mapping->a_ops = &ll_aops;
390 } else if (S_ISDIR(inode->i_mode)) {
391 inode->i_op = &ll_dir_inode_operations;
392 inode->i_fop = &ll_dir_operations;
393 inode->i_mapping->a_ops = &ll_dir_aops;
395 } else if (S_ISLNK(inode->i_mode)) {
396 inode->i_op = &ll_fast_symlink_inode_operations;
399 init_special_inode(inode, inode->i_mode,
400 ((int *)ll_i2info(inode)->lli_inline)[0]);
407 /* exported operations */
408 struct super_operations ll_super_operations =
410 read_inode2: ll_read_inode2,
411 delete_inode: ll_delete_inode,
412 put_super: ll_put_super,
416 struct file_system_type lustre_lite_fs_type = {
417 "lustre_lite", 0, ll_read_super, NULL
420 static int __init init_lustre_lite(void)
422 printk(KERN_INFO "Lustre Lite 0.0.1, braam@clusterfs.com\n");
423 ll_file_data_slab = kmem_cache_create("ll_file_data",
424 sizeof(struct ll_file_data), 0,
425 SLAB_HWCACHE_ALIGN, NULL, NULL);
426 if (ll_file_data_slab == NULL)
428 return register_filesystem(&lustre_lite_fs_type);
431 static void __exit exit_lustre_lite(void)
433 unregister_filesystem(&lustre_lite_fs_type);
434 kmem_cache_destroy(ll_file_data_slab);
437 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
438 MODULE_DESCRIPTION("Lustre Lite Client File System v1.0");
439 MODULE_LICENSE("GPL");
441 module_init(init_lustre_lite);
442 module_exit(exit_lustre_lite);