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 #include <linux/config.h>
18 #include <linux/module.h>
19 #include <linux/kernel.h>
21 #include <linux/string.h>
22 #include <linux/stat.h>
23 #include <linux/errno.h>
24 #include <linux/locks.h>
25 #include <linux/unistd.h>
27 #include <asm/system.h>
28 #include <asm/uaccess.h>
31 #include <linux/stat.h>
32 #include <asm/uaccess.h>
33 #include <asm/segment.h>
35 #define DEBUG_SUBSYSTEM S_LLITE
37 #include <linux/lustre_lite.h>
39 kmem_cache_t *ll_file_data_slab;
40 extern struct address_space_operations ll_aops;
41 extern struct address_space_operations ll_dir_aops;
42 struct super_operations ll_super_operations;
44 static struct lustre_ha_mgr *llite_ha_mgr;
46 static char *ll_read_opt(const char *opt, char *data)
52 CDEBUG(D_INFO, "option: %s, data %s\n", opt, data);
53 if ( strncmp(opt, data, strlen(opt)) ) {
57 if ( (value = strchr(data, '=')) == NULL ) {
63 OBD_ALLOC(retval, strlen(value) + 1);
65 CERROR("out of memory!\n");
69 memcpy(retval, value, strlen(value)+1);
70 CDEBUG(D_SUPER, "Assigned option: %s, value %s\n", opt, retval);
75 static void ll_options(char *options, char **dev, char **vers)
85 for (this_char = strtok (options, ",");
87 this_char = strtok (NULL, ",")) {
88 CDEBUG(D_INFO, "this_char %s\n", this_char);
89 if ( (!*dev && (*dev = ll_read_opt("device", this_char)))||
90 (!*vers && (*vers = ll_read_opt("version", this_char))) )
96 static struct super_block * ll_read_super(struct super_block *sb,
97 void *data, int silent)
99 struct inode *root = 0;
100 struct ll_sb_info *sbi;
102 char *version = NULL;
105 struct ptlrpc_request *request = NULL;
110 OBD_ALLOC(sbi, sizeof(*sbi));
116 sb->u.generic_sbp = sbi;
118 ll_options(data, &device, &version);
121 CERROR("no device\n");
122 GOTO(out_free, sb = NULL);
125 devno = simple_strtoul(device, NULL, 0);
126 if ( devno >= MAX_OBD_DEVICES ) {
127 CERROR("device of %s too high\n", device);
128 GOTO(out_free, sb = NULL);
131 sbi->ll_conn.oc_dev = &obd_dev[devno];
132 err = obd_connect(&sbi->ll_conn);
134 CERROR("cannot connect to %s\n", device);
135 GOTO(out_free, sb = NULL);
138 /* the first parameter should become an mds device no */
139 ptlrpc_init_client(llite_ha_mgr, MDS_REQUEST_PORTAL, MDC_REPLY_PORTAL,
140 &sbi->ll_mds_client);
141 err = ptlrpc_connect_client("mds", &sbi->ll_mds_client,
144 CERROR("cannot find MDS\n");
145 GOTO(out_disc, sb = NULL);
150 sbi->ll_ha_mgr = llite_ha_mgr;
152 sb->s_maxbytes = 1LL << 36;
153 sb->s_blocksize = PAGE_SIZE;
154 sb->s_blocksize_bits = (unsigned char)PAGE_SHIFT;
155 sb->s_magic = LL_SUPER_MAGIC;
156 sb->s_op = &ll_super_operations;
158 /* make root inode */
159 err = mdc_getattr(&sbi->ll_mds_client, &sbi->ll_mds_peer,
160 sbi->ll_rootino, S_IFDIR,
161 OBD_MD_FLNOTOBD|OBD_MD_FLBLOCKS, &request);
163 CERROR("mdc_getattr failed for root %d\n", err);
164 GOTO(out_req, sb = NULL);
167 root = iget4(sb, sbi->ll_rootino, NULL,
168 lustre_msg_buf(request->rq_repmsg, 0));
170 sb->s_root = d_alloc_root(root);
172 CERROR("lustre_lite: bad iget4 for root\n");
173 GOTO(out_req, sb = NULL);
177 ptlrpc_free_req(request);
180 obd_disconnect(&sbi->ll_conn);
183 OBD_FREE(sbi, sizeof(*sbi));
186 OBD_FREE(device, strlen(device) + 1);
188 OBD_FREE(version, strlen(version) + 1);
191 } /* ll_read_super */
193 static void ll_put_super(struct super_block *sb)
195 struct ll_sb_info *sbi = sb->u.generic_sbp;
197 obd_disconnect(&sbi->ll_conn);
198 OBD_FREE(sb->u.generic_sbp, sizeof(*sbi));
204 extern inline struct obdo * ll_oa_from_inode(struct inode *inode, int valid);
205 static void ll_delete_inode(struct inode *inode)
207 if (S_ISREG(inode->i_mode)) {
210 oa = ll_oa_from_inode(inode, OBD_MD_FLNOTOBD);
212 CERROR("no memory\n");
215 err = obd_destroy(ll_i2obdconn(inode), oa);
216 CDEBUG(D_INODE, "obd destroy of %Ld error %d\n",
224 /* like inode_setattr, but doesn't mark the inode dirty */
225 static int ll_attr2inode(struct inode * inode, struct iattr * attr, int trunc)
227 unsigned int ia_valid = attr->ia_valid;
230 if ((ia_valid & ATTR_SIZE) && trunc ) {
231 error = vmtruncate(inode, attr->ia_size);
234 } else if (ia_valid & ATTR_SIZE) {
235 inode->i_size = attr->ia_size;
238 if (ia_valid & ATTR_UID)
239 inode->i_uid = attr->ia_uid;
240 if (ia_valid & ATTR_GID)
241 inode->i_gid = attr->ia_gid;
242 if (ia_valid & ATTR_ATIME)
243 inode->i_atime = attr->ia_atime;
244 if (ia_valid & ATTR_MTIME)
245 inode->i_mtime = attr->ia_mtime;
246 if (ia_valid & ATTR_CTIME)
247 inode->i_ctime = attr->ia_ctime;
248 if (ia_valid & ATTR_MODE) {
249 inode->i_mode = attr->ia_mode;
250 if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID))
251 inode->i_mode &= ~S_ISGID;
257 int ll_inode_setattr(struct inode *inode, struct iattr *attr, int do_trunc)
259 struct ptlrpc_request *request;
260 struct ll_sb_info *sbi = ll_i2sbi(inode);
265 /* change incore inode */
266 ll_attr2inode(inode, attr, do_trunc);
268 err = mdc_setattr(&sbi->ll_mds_client, &sbi->ll_mds_peer, inode, attr,
271 CERROR("mdc_setattr fails (%d)\n", err);
273 ptlrpc_free_req(request);
279 int ll_setattr(struct dentry *de, struct iattr *attr)
281 return ll_inode_setattr(de->d_inode, attr, 1);
284 static int ll_statfs(struct super_block *sb, struct statfs *buf)
291 err = obd_statfs(ID(sb), &tmp);
293 CERROR("obd_statfs fails (%d)\n", err);
296 memcpy(buf, &tmp, sizeof(*buf));
297 CDEBUG(D_SUPER, "statfs returns avail %ld\n", tmp.f_bavail);
303 static void inline ll_to_inode(struct inode *dst, struct mds_body *body)
305 struct ll_inode_info *ii =
306 (struct ll_inode_info *) &dst->u.generic_ip;
308 /* core attributes first */
309 if ( body->valid & OBD_MD_FLID )
310 dst->i_ino = body->ino;
311 if ( body->valid & OBD_MD_FLATIME )
312 dst->i_atime = body->atime;
313 if ( body->valid & OBD_MD_FLMTIME )
314 dst->i_mtime = body->mtime;
315 if ( body->valid & OBD_MD_FLCTIME )
316 dst->i_ctime = body->ctime;
317 if ( body->valid & OBD_MD_FLSIZE )
318 dst->i_size = body->size;
319 if ( body->valid & OBD_MD_FLMODE )
320 dst->i_mode = body->mode;
321 if ( body->valid & OBD_MD_FLUID )
322 dst->i_uid = body->uid;
323 if ( body->valid & OBD_MD_FLGID )
324 dst->i_gid = body->gid;
325 if ( body->valid & OBD_MD_FLFLAGS )
326 dst->i_flags = body->flags;
327 if ( body->valid & OBD_MD_FLNLINK )
328 dst->i_nlink = body->nlink;
329 if ( body->valid & OBD_MD_FLGENER )
330 dst->i_generation = body->generation;
332 /* this will become more elaborate for striping etc */
333 if (body->valid & OBD_MD_FLOBJID)
334 ii->lli_objid = body->objid;
337 if (obdo_has_inline(oa)) {
338 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) ||
339 S_ISFIFO(inode->i_mode)) {
340 obd_rdev rdev = *((obd_rdev *)oa->o_inline);
342 "copying device %x from obdo to inode\n", rdev);
343 init_special_inode(inode, inode->i_mode, rdev);
345 CDEBUG(D_INFO, "copying inline from obdo to inode\n");
346 memcpy(oinfo->lli_inline, oa->o_inline, OBD_INLINESZ);
348 oinfo->lli_flags |= OBD_FL_INLINEDATA;
353 static inline void ll_read_inode2(struct inode *inode, void *opaque)
355 struct mds_body *body = opaque;
358 ll_to_inode(inode, body);
360 /* OIDEBUG(inode); */
362 if (S_ISREG(inode->i_mode)) {
363 inode->i_op = &ll_file_inode_operations;
364 inode->i_fop = &ll_file_operations;
365 inode->i_mapping->a_ops = &ll_aops;
367 } else if (S_ISDIR(inode->i_mode)) {
368 inode->i_op = &ll_dir_inode_operations;
369 inode->i_fop = &ll_dir_operations;
370 inode->i_mapping->a_ops = &ll_dir_aops;
372 } else if (S_ISLNK(inode->i_mode)) {
373 inode->i_op = &ll_fast_symlink_inode_operations;
376 init_special_inode(inode, inode->i_mode,
377 ((int *)ll_i2info(inode)->lli_inline)[0]);
384 /* exported operations */
385 struct super_operations ll_super_operations =
387 read_inode2: ll_read_inode2,
388 delete_inode: ll_delete_inode,
389 put_super: ll_put_super,
393 struct file_system_type lustre_lite_fs_type = {
394 "lustre_lite", 0, ll_read_super, NULL
397 static int llite_setup(struct obd_device *dev, obd_count len, void *buf)
403 static int llite_cleanup(struct obd_device *dev)
409 /* use obd ops to offer management infrastructure */
410 static struct obd_ops llite_obd_ops = {
411 o_setup: llite_setup,
412 o_cleanup: llite_cleanup,
415 static int __init init_lustre_lite(void)
417 printk(KERN_INFO "Lustre Lite 0.0.1, braam@clusterfs.com\n");
418 obd_register_type(&llite_obd_ops, LUSTRE_LITE_NAME);
419 ll_file_data_slab = kmem_cache_create("ll_file_data",
420 sizeof(struct ll_file_data), 0,
421 SLAB_HWCACHE_ALIGN, NULL, NULL);
422 if (ll_file_data_slab == NULL)
425 llite_ha_mgr = llite_ha_setup();
426 return register_filesystem(&lustre_lite_fs_type);
429 static void __exit exit_lustre_lite(void)
431 unregister_filesystem(&lustre_lite_fs_type);
432 llite_ha_cleanup(llite_ha_mgr);
433 kmem_cache_destroy(ll_file_data_slab);
434 obd_unregister_type(LUSTRE_LITE_NAME);
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);