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>
20 #define DEBUG_SUBSYSTEM S_LLITE
22 #include <linux/lustre_lite.h>
23 #include <linux/lustre_ha.h>
25 kmem_cache_t *ll_file_data_slab;
26 extern struct address_space_operations ll_aops;
27 extern struct address_space_operations ll_dir_aops;
28 struct super_operations ll_super_operations;
29 extern int ll_commitcbd_setup(struct ll_sb_info *);
30 extern int ll_commitcbd_cleanup(struct ll_sb_info *);
32 static char *ll_read_opt(const char *opt, char *data)
38 CDEBUG(D_INFO, "option: %s, data %s\n", opt, data);
39 if ( strncmp(opt, data, strlen(opt)) )
41 if ( (value = strchr(data, '=')) == NULL )
45 OBD_ALLOC(retval, strlen(value) + 1);
47 CERROR("out of memory!\n");
51 memcpy(retval, value, strlen(value)+1);
52 CDEBUG(D_SUPER, "Assigned option: %s, value %s\n", opt, retval);
56 static void ll_options(char *options, char **dev, char **vers)
66 for (this_char = strtok (options, ",");
68 this_char = strtok (NULL, ",")) {
69 CDEBUG(D_INFO, "this_char %s\n", this_char);
70 if ( (!*dev && (*dev = ll_read_opt("device", this_char)))||
71 (!*vers && (*vers = ll_read_opt("version", this_char))) )
77 static struct super_block * ll_read_super(struct super_block *sb,
78 void *data, int silent)
80 struct inode *root = 0;
81 struct ll_sb_info *sbi;
86 struct ll_fid rootfid;
87 struct ptlrpc_request *request = NULL;
92 OBD_ALLOC(sbi, sizeof(*sbi));
98 sb->u.generic_sbp = sbi;
100 ll_options(data, &device, &version);
103 CERROR("no device\n");
104 GOTO(out_free, sb = NULL);
107 devno = simple_strtoul(device, NULL, 0);
108 if ( devno >= MAX_OBD_DEVICES ) {
109 CERROR("device of %s too high\n", device);
110 GOTO(out_free, sb = NULL);
113 sbi->ll_conn.oc_dev = &obd_dev[devno];
114 err = obd_connect(&sbi->ll_conn);
116 CERROR("cannot connect to %s\n", device);
117 GOTO(out_free, sb = NULL);
120 ptlrpc_init_client(ptlrpc_connmgr, MDS_REQUEST_PORTAL, MDC_REPLY_PORTAL,
121 &sbi->ll_mds_client);
123 sbi->ll_mds_conn = ptlrpc_uuid_to_connection("mds");
124 if (!sbi->ll_mds_conn) {
125 CERROR("cannot find MDS\n");
126 GOTO(out_disc, sb = NULL);
129 err = connmgr_connect(ptlrpc_connmgr, sbi->ll_mds_conn);
131 CERROR("cannot connect to MDS\n");
132 ptlrpc_put_connection(sbi->ll_mds_conn);
133 GOTO(out_disc, sb = NULL);
136 sbi->ll_mds_conn->c_level = LUSTRE_CONN_FULL;
138 err= mdc_connect(&sbi->ll_mds_client, sbi->ll_mds_conn,
140 CERROR("rootfid %Ld\n", rootfid.id);
142 CERROR("cannot mds_connect %d\n", err);
143 GOTO(out_disc, sb = NULL);
145 sbi->ll_rootino = rootfid.id;
147 sb->s_maxbytes = 1ULL << 36;
148 sb->s_blocksize = PAGE_SIZE;
149 sb->s_blocksize_bits = (unsigned char)PAGE_SHIFT;
150 sb->s_magic = LL_SUPER_MAGIC;
151 sb->s_op = &ll_super_operations;
153 /* make root inode */
154 err = mdc_getattr(&sbi->ll_mds_client, sbi->ll_mds_conn,
155 sbi->ll_rootino, S_IFDIR,
156 OBD_MD_FLNOTOBD|OBD_MD_FLBLOCKS, &request);
158 CERROR("mdc_getattr failed for root %d\n", err);
159 GOTO(out_req, sb = NULL);
162 /* initialize committed transaction callback daemon */
163 INIT_LIST_HEAD(&sbi->ll_commitcbd_not_committed);
164 spin_lock_init(&sbi->ll_commitcbd_lock);
165 init_waitqueue_head(&sbi->ll_commitcbd_waitq);
166 init_waitqueue_head(&sbi->ll_commitcbd_ctl_waitq);
167 sbi->ll_commitcbd_flags = 0;
168 err = ll_commitcbd_setup(sbi);
170 CERROR("failed to start commit callback daemon\n");
171 GOTO(out_req, sb = NULL);
174 root = iget4(sb, sbi->ll_rootino, NULL,
175 lustre_msg_buf(request->rq_repmsg, 0));
177 sb->s_root = d_alloc_root(root);
179 CERROR("lustre_lite: bad iget4 for root\n");
180 GOTO(out_req, sb = NULL);
184 ptlrpc_free_req(request);
187 obd_disconnect(&sbi->ll_conn);
190 OBD_FREE(sbi, sizeof(*sbi));
193 OBD_FREE(device, strlen(device) + 1);
195 OBD_FREE(version, strlen(version) + 1);
198 } /* ll_read_super */
200 static void ll_put_super(struct super_block *sb)
202 struct ll_sb_info *sbi = sb->u.generic_sbp;
204 ll_commitcbd_cleanup(sbi);
205 obd_disconnect(&sbi->ll_conn);
206 ptlrpc_put_connection(sbi->ll_mds_conn);
207 OBD_FREE(sb->u.generic_sbp, sizeof(*sbi));
213 extern inline struct obdo * ll_oa_from_inode(struct inode *inode, int valid);
214 static void ll_delete_inode(struct inode *inode)
216 if (S_ISREG(inode->i_mode)) {
219 oa = ll_oa_from_inode(inode, OBD_MD_FLNOTOBD);
221 CERROR("no memory\n");
224 err = obd_destroy(ll_i2obdconn(inode), oa);
225 CDEBUG(D_INODE, "obd destroy of %Ld error %d\n",
226 (unsigned long long)oa->o_id, err);
233 /* like inode_setattr, but doesn't mark the inode dirty */
234 static int ll_attr2inode(struct inode * inode, struct iattr * attr, int trunc)
236 unsigned int ia_valid = attr->ia_valid;
239 if ((ia_valid & ATTR_SIZE) && trunc ) {
240 error = vmtruncate(inode, attr->ia_size);
243 } else if (ia_valid & ATTR_SIZE) {
244 inode->i_size = attr->ia_size;
247 if (ia_valid & ATTR_UID)
248 inode->i_uid = attr->ia_uid;
249 if (ia_valid & ATTR_GID)
250 inode->i_gid = attr->ia_gid;
251 if (ia_valid & ATTR_ATIME)
252 inode->i_atime = attr->ia_atime;
253 if (ia_valid & ATTR_MTIME)
254 inode->i_mtime = attr->ia_mtime;
255 if (ia_valid & ATTR_CTIME)
256 inode->i_ctime = attr->ia_ctime;
257 if (ia_valid & ATTR_MODE) {
258 inode->i_mode = attr->ia_mode;
259 if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID))
260 inode->i_mode &= ~S_ISGID;
266 int ll_inode_setattr(struct inode *inode, struct iattr *attr, int do_trunc)
268 struct ptlrpc_request *request = NULL;
269 struct ll_sb_info *sbi = ll_i2sbi(inode);
274 /* change incore inode */
275 ll_attr2inode(inode, attr, do_trunc);
277 err = mdc_setattr(&sbi->ll_mds_client, sbi->ll_mds_conn, inode, attr,
280 CERROR("mdc_setattr fails (%d)\n", err);
282 ptlrpc_free_req(request);
287 int ll_setattr(struct dentry *de, struct iattr *attr)
289 return ll_inode_setattr(de->d_inode, attr, 1);
292 static int ll_statfs(struct super_block *sb, struct statfs *buf)
298 err = obd_statfs(&ll_s2sbi(sb)->ll_conn, &tmp);
300 CERROR("obd_statfs fails (%d)\n", err);
303 memcpy(buf, &tmp, sizeof(*buf));
304 CDEBUG(D_SUPER, "statfs returns avail %ld\n", tmp.f_bavail);
309 static void inline ll_to_inode(struct inode *dst, struct mds_body *body)
311 struct ll_inode_info *ii =
312 (struct ll_inode_info *) &dst->u.generic_ip;
314 /* core attributes first */
315 if ( body->valid & OBD_MD_FLID )
316 dst->i_ino = body->ino;
317 if ( body->valid & OBD_MD_FLATIME )
318 dst->i_atime = body->atime;
319 if ( body->valid & OBD_MD_FLMTIME )
320 dst->i_mtime = body->mtime;
321 if ( body->valid & OBD_MD_FLCTIME )
322 dst->i_ctime = body->ctime;
323 if ( body->valid & OBD_MD_FLSIZE )
324 dst->i_size = body->size;
325 if ( body->valid & OBD_MD_FLMODE )
326 dst->i_mode = body->mode;
327 if ( body->valid & OBD_MD_FLUID )
328 dst->i_uid = body->uid;
329 if ( body->valid & OBD_MD_FLGID )
330 dst->i_gid = body->gid;
331 if ( body->valid & OBD_MD_FLFLAGS )
332 dst->i_flags = body->flags;
333 if ( body->valid & OBD_MD_FLNLINK )
334 dst->i_nlink = body->nlink;
335 if ( body->valid & OBD_MD_FLGENER )
336 dst->i_generation = body->generation;
338 /* this will become more elaborate for striping etc */
339 if (body->valid & OBD_MD_FLOBJID)
340 ii->lli_objid = body->objid;
343 if (obdo_has_inline(oa)) {
344 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) ||
345 S_ISFIFO(inode->i_mode)) {
346 obd_rdev rdev = *((obd_rdev *)oa->o_inline);
348 "copying device %x from obdo to inode\n", rdev);
349 init_special_inode(inode, inode->i_mode, rdev);
351 CDEBUG(D_INFO, "copying inline from obdo to inode\n");
352 memcpy(oinfo->lli_inline, oa->o_inline, OBD_INLINESZ);
354 oinfo->lli_flags |= OBD_FL_INLINEDATA;
359 static inline void ll_read_inode2(struct inode *inode, void *opaque)
361 struct mds_body *body = opaque;
364 ll_to_inode(inode, body);
366 /* OIDEBUG(inode); */
368 if (S_ISREG(inode->i_mode)) {
369 inode->i_op = &ll_file_inode_operations;
370 inode->i_fop = &ll_file_operations;
371 inode->i_mapping->a_ops = &ll_aops;
373 } else if (S_ISDIR(inode->i_mode)) {
374 inode->i_op = &ll_dir_inode_operations;
375 inode->i_fop = &ll_dir_operations;
376 inode->i_mapping->a_ops = &ll_dir_aops;
378 } else if (S_ISLNK(inode->i_mode)) {
379 inode->i_op = &ll_fast_symlink_inode_operations;
382 init_special_inode(inode, inode->i_mode,
383 ((int *)ll_i2info(inode)->lli_inline)[0]);
390 /* exported operations */
391 struct super_operations ll_super_operations =
393 read_inode2: ll_read_inode2,
394 delete_inode: ll_delete_inode,
395 put_super: ll_put_super,
399 struct file_system_type lustre_lite_fs_type = {
400 "lustre_lite", 0, ll_read_super, NULL
403 static int __init init_lustre_lite(void)
405 printk(KERN_INFO "Lustre Lite 0.0.1, braam@clusterfs.com\n");
406 ll_file_data_slab = kmem_cache_create("ll_file_data",
407 sizeof(struct ll_file_data), 0,
408 SLAB_HWCACHE_ALIGN, NULL, NULL);
409 if (ll_file_data_slab == NULL)
411 return register_filesystem(&lustre_lite_fs_type);
414 static void __exit exit_lustre_lite(void)
416 unregister_filesystem(&lustre_lite_fs_type);
417 kmem_cache_destroy(ll_file_data_slab);
420 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
421 MODULE_DESCRIPTION("Lustre Lite Client File System v1.0");
422 MODULE_LICENSE("GPL");
424 module_init(init_lustre_lite);
425 module_exit(exit_lustre_lite);