2 * OBDFS Super operations
4 * Copryright (C) 1996 Peter J. Braam <braam@stelias.com>
9 #include <linux/config.h>
10 #include <linux/module.h>
11 #include <linux/kernel.h>
13 #include <linux/string.h>
14 #include <linux/stat.h>
15 #include <linux/errno.h>
16 #include <linux/locks.h>
17 #include <linux/unistd.h>
19 #include <asm/system.h>
20 #include <asm/uaccess.h>
23 #include <linux/stat.h>
24 #include <asm/uaccess.h>
25 #include <linux/vmalloc.h>
26 #include <asm/segment.h>
28 #include <../obd/linux/sim_obd.h>
32 #undef MOD_INC_USE_COUNT
33 #define MOD_INC_USE_COUNT
34 #undef MOD_DEC_USE_COUNT
35 #define MOD_DEC_USE_COUNT
37 /* VFS super_block ops */
38 static struct super_block *obdfs_read_super(struct super_block *, void *, int);
39 static void obdfs_read_inode(struct inode *);
40 static int obdfs_notify_change(struct dentry *dentry, struct iattr *attr);
41 static void obdfs_write_inode(struct inode *);
42 static void obdfs_delete_inode(struct inode *);
43 static void obdfs_put_super(struct super_block *);
44 static int obdfs_statfs(struct super_block *sb, struct statfs *buf,
47 /* exported operations */
48 struct super_operations obdfs_super_operations =
50 obdfs_read_inode, /* read_inode */
51 obdfs_write_inode, /* write_inode */
53 obdfs_delete_inode, /* delete_inode */
54 obdfs_notify_change, /* notify_change */
55 obdfs_put_super, /* put_super */
56 NULL, /* write_super */
57 obdfs_statfs, /* statfs */
61 struct obdfs_sb_info obdfs_super_info;
65 static struct super_block * obdfs_read_super(struct super_block *sb,
66 void *data, int silent)
68 struct inode *root = 0;
69 struct obdfs_sb_info *sbi = NULL;
75 sbi = &obdfs_super_info;
77 if ( sbi->osi_super ) {
78 printk("Already mounted\n");
83 error = obd_connect(obd_minor, &sbi->osi_conn_info);
85 printk("OBDFS: cannot connect to 0x%x.\n", obd_minor);
91 sb->u.generic_sbp = sbi;
92 sb->s_blocksize = sbi->osi_conn_info.conn_blocksize;
93 sb->s_blocksize_bits = sbi->osi_conn_info.conn_blocksize_bits;
94 sb->s_magic = OBDFS_SUPER_MAGIC;
95 sb->s_op = &obdfs_super_operations;
98 root = iget(sb, sbi->osi_conn_info.conn_ino);
99 if (!root || is_bad_inode(root)) {
100 printk("OBDFS: bad iget for root\n");
107 printk("obdfs_read_super: rootinode is %ld dev %d\n",
108 root->i_ino, root->i_dev);
109 sb->s_root = d_alloc_root(root, NULL);
118 sbi->osi_super = NULL;
127 static void obdfs_put_super(struct super_block *sb)
129 struct obdfs_sb_info *sbi;
136 /* XXX flush stuff */
137 sbi = sb->u.generic_sbp;
138 sb->u.generic_sbp = NULL;
139 obd_disconnect(sbi->osi_conn_info.conn_id);
140 sbi->osi_super = NULL;
143 printk("OBDFS: Bye bye.\n");
144 memset(sbi, 0, sizeof(* sbi));
150 /* all filling in of inodes postponed until lookup */
151 static void obdfs_read_inode(struct inode *inode)
155 struct obdfs_sb_info *sbi = inode->i_sb->u.generic_sbp;
158 error = obd_getattr(sbi->osi_conn_info.conn_id, inode->i_ino, &attr);
160 printk("obdfs_read_inode: ibd_getattr fails (%d)\n", error);
164 inode_setattr(inode, &attr);
169 static void inode_to_iattr(struct inode *inode, struct iattr *tmp)
171 tmp->ia_mode = inode->i_mode;
172 tmp->ia_uid = inode->i_uid;
173 tmp->ia_gid = inode->i_gid;
174 tmp->ia_size = inode->i_size;
175 tmp->ia_atime = inode->i_atime;
176 tmp->ia_mtime = inode->i_mtime;
177 tmp->ia_ctime = inode->i_ctime;
178 tmp->ia_attr_flags = inode->i_flags;
183 static void obdfs_write_inode(struct inode *inode)
185 struct obdfs_sb_info *sbi;
190 inode_to_iattr(inode, &attr);
191 sbi = inode->i_sb->u.generic_sbp;
192 error = obd_setattr(sbi->osi_conn_info.conn_id, inode->i_ino, &attr);
194 printk("obdfs_write_inode: ibd_setattr fails (%d)\n", error);
201 static void obdfs_delete_inode(struct inode *inode)
203 struct obdfs_sb_info *sbi;
207 sbi = inode->i_sb->u.generic_sbp;
208 error = obd_destroy(sbi->osi_conn_info.conn_id , inode->i_ino);
210 printk("obdfs_delete_node: ibd_destroy fails (%d)\n", error);
217 static int obdfs_notify_change(struct dentry *de, struct iattr *iattr)
219 struct inode *inode = de->d_inode;
220 struct obdfs_sb_info * sbi;
225 sbi = inode->i_sb->u.generic_sbp;
226 error = obd_setattr(sbi->osi_conn_info.conn_id, inode->i_ino, iattr);
228 printk("obdfs_notify_change: obd_setattr fails (%d)\n", error);
231 inode_setattr(inode, iattr);
238 static int obdfs_statfs(struct super_block *sb, struct statfs *buf,
242 struct obdfs_sb_info * sbi;
247 sbi = sb->u.generic_sbp;
248 error = obd_statfs(sbi->osi_conn_info.conn_id, &tmp);
250 printk("obdfs_notify_change: obd_statfs fails (%d)\n", error);
253 copy_to_user(buf, &tmp, (bufsize<sizeof(tmp)) ? bufsize : sizeof(tmp));
260 struct file_system_type obdfs_fs_type = {
261 "obdfs", 0, obdfs_read_super, NULL
266 printk(KERN_INFO "OBDFS v0.1, braam@stelias.com\n");
269 return register_filesystem(&obdfs_fs_type);
274 int init_module(void)
279 void cleanup_module(void)
283 obdfs_sysctl_clean();
285 void obdfs_psdev_dec_use_count(void)
290 EXPORT_SYMBOL(obdfs_psdev_dec_use_count);