Blame view
fs/coda/inode.c
7.29 KB
1da177e4c Linux-2.6.12-rc2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
/* * Super block/filesystem wide operations * * Copyright (C) 1996 Peter J. Braam <braam@maths.ox.ac.uk> and * Michael Callahan <callahan@maths.ox.ac.uk> * * Rewritten for Linux 2.1. Peter Braam <braam@cs.cmu.edu> * Copyright (C) Carnegie Mellon University */ #include <linux/module.h> #include <linux/kernel.h> #include <linux/mm.h> #include <linux/string.h> #include <linux/stat.h> #include <linux/errno.h> #include <linux/unistd.h> |
da47c19e5 Coda: replace BKL... |
18 |
#include <linux/mutex.h> |
b5ce1d83a Coda: add spin lo... |
19 |
#include <linux/spinlock.h> |
1da177e4c Linux-2.6.12-rc2 |
20 21 |
#include <linux/file.h> #include <linux/vfs.h> |
5a0e3ad6a include cleanup: ... |
22 |
#include <linux/slab.h> |
9fd973e08 coda: Restrict co... |
23 |
#include <linux/pid_namespace.h> |
834b46c37 fs/coda: use linu... |
24 |
#include <linux/uaccess.h> |
1da177e4c Linux-2.6.12-rc2 |
25 26 27 28 |
#include <linux/fs.h> #include <linux/vmalloc.h> #include <linux/coda.h> |
1da177e4c Linux-2.6.12-rc2 |
29 |
#include <linux/coda_psdev.h> |
31a203df9 take coda-private... |
30 31 |
#include "coda_linux.h" #include "coda_cache.h" |
1da177e4c Linux-2.6.12-rc2 |
32 |
|
c98d8cfbc [PATCH] fs/coda/:... |
33 |
#include "coda_int.h" |
1da177e4c Linux-2.6.12-rc2 |
34 |
/* VFS super_block ops */ |
b57922d97 convert remaining... |
35 |
static void coda_evict_inode(struct inode *); |
1da177e4c Linux-2.6.12-rc2 |
36 |
static void coda_put_super(struct super_block *); |
726c33422 [PATCH] VFS: Perm... |
37 |
static int coda_statfs(struct dentry *dentry, struct kstatfs *buf); |
1da177e4c Linux-2.6.12-rc2 |
38 |
|
e18b890bb [PATCH] slab: rem... |
39 |
static struct kmem_cache * coda_inode_cachep; |
1da177e4c Linux-2.6.12-rc2 |
40 41 42 43 |
static struct inode *coda_alloc_inode(struct super_block *sb) { struct coda_inode_info *ei; |
747fecab3 coda: kill redund... |
44 |
ei = kmem_cache_alloc(coda_inode_cachep, GFP_KERNEL); |
1da177e4c Linux-2.6.12-rc2 |
45 46 47 48 |
if (!ei) return NULL; memset(&ei->c_fid, 0, sizeof(struct CodaFid)); ei->c_flags = 0; |
17499e332 coda: Cache permi... |
49 |
ei->c_uid = GLOBAL_ROOT_UID; |
1da177e4c Linux-2.6.12-rc2 |
50 |
ei->c_cached_perm = 0; |
b5ce1d83a Coda: add spin lo... |
51 |
spin_lock_init(&ei->c_lock); |
1da177e4c Linux-2.6.12-rc2 |
52 53 |
return &ei->vfs_inode; } |
fa0d7e3de fs: icache RCU fr... |
54 |
static void coda_i_callback(struct rcu_head *head) |
1da177e4c Linux-2.6.12-rc2 |
55 |
{ |
fa0d7e3de fs: icache RCU fr... |
56 |
struct inode *inode = container_of(head, struct inode, i_rcu); |
1da177e4c Linux-2.6.12-rc2 |
57 58 |
kmem_cache_free(coda_inode_cachep, ITOC(inode)); } |
fa0d7e3de fs: icache RCU fr... |
59 60 61 62 |
static void coda_destroy_inode(struct inode *inode) { call_rcu(&inode->i_rcu, coda_i_callback); } |
51cc50685 SL*B: drop kmem c... |
63 |
static void init_once(void *foo) |
1da177e4c Linux-2.6.12-rc2 |
64 65 |
{ struct coda_inode_info *ei = (struct coda_inode_info *) foo; |
a35afb830 Remove SLAB_CTOR_... |
66 |
inode_init_once(&ei->vfs_inode); |
1da177e4c Linux-2.6.12-rc2 |
67 |
} |
20c2df83d mm: Remove slab d... |
68 |
|
5f356fd4d fs/coda/inode.c: ... |
69 |
int __init coda_init_inodecache(void) |
1da177e4c Linux-2.6.12-rc2 |
70 71 |
{ coda_inode_cachep = kmem_cache_create("coda_inode_cache", |
5d097056c kmemcg: account c... |
72 73 74 |
sizeof(struct coda_inode_info), 0, SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD| SLAB_ACCOUNT, init_once); |
1da177e4c Linux-2.6.12-rc2 |
75 76 77 78 79 80 81 |
if (coda_inode_cachep == NULL) return -ENOMEM; return 0; } void coda_destroy_inodecache(void) { |
8c0a85377 fs: push rcu_barr... |
82 83 84 85 86 |
/* * Make sure all delayed rcu free inodes are flushed before we * destroy cache. */ rcu_barrier(); |
1a1d92c10 [PATCH] Really ig... |
87 |
kmem_cache_destroy(coda_inode_cachep); |
1da177e4c Linux-2.6.12-rc2 |
88 89 90 91 |
} static int coda_remount(struct super_block *sb, int *flags, char *data) { |
02b9984d6 fs: push sync_fil... |
92 |
sync_filesystem(sb); |
fac1f0e34 coda: coda doesn'... |
93 |
*flags |= MS_NOATIME; |
1da177e4c Linux-2.6.12-rc2 |
94 95 96 97 |
return 0; } /* exported operations */ |
ee9b6d61a [PATCH] Mark stru... |
98 |
static const struct super_operations coda_super_operations = |
1da177e4c Linux-2.6.12-rc2 |
99 100 101 |
{ .alloc_inode = coda_alloc_inode, .destroy_inode = coda_destroy_inode, |
b57922d97 convert remaining... |
102 |
.evict_inode = coda_evict_inode, |
1da177e4c Linux-2.6.12-rc2 |
103 104 105 106 107 108 109 |
.put_super = coda_put_super, .statfs = coda_statfs, .remount_fs = coda_remount, }; static int get_device_index(struct coda_mount_data *data) { |
2903ff019 switch simple cas... |
110 |
struct fd f; |
1da177e4c Linux-2.6.12-rc2 |
111 |
struct inode *inode; |
2903ff019 switch simple cas... |
112 |
int idx; |
1da177e4c Linux-2.6.12-rc2 |
113 |
|
78f7d75e5 switch coda get_d... |
114 |
if (data == NULL) { |
6d6bd94f4 fs/coda: use __fu... |
115 116 |
pr_warn("%s: Bad mount data ", __func__); |
1da177e4c Linux-2.6.12-rc2 |
117 118 |
return -1; } |
78f7d75e5 switch coda get_d... |
119 |
if (data->version != CODA_MOUNT_VERSION) { |
6d6bd94f4 fs/coda: use __fu... |
120 121 |
pr_warn("%s: Bad mount version ", __func__); |
1da177e4c Linux-2.6.12-rc2 |
122 123 |
return -1; } |
2903ff019 switch simple cas... |
124 125 |
f = fdget(data->fd); if (!f.file) |
78f7d75e5 switch coda get_d... |
126 |
goto Ebadf; |
496ad9aa8 new helper: file_... |
127 |
inode = file_inode(f.file); |
78f7d75e5 switch coda get_d... |
128 |
if (!S_ISCHR(inode->i_mode) || imajor(inode) != CODA_PSDEV_MAJOR) { |
2903ff019 switch simple cas... |
129 |
fdput(f); |
78f7d75e5 switch coda get_d... |
130 |
goto Ebadf; |
1da177e4c Linux-2.6.12-rc2 |
131 132 133 |
} idx = iminor(inode); |
2903ff019 switch simple cas... |
134 |
fdput(f); |
1da177e4c Linux-2.6.12-rc2 |
135 |
|
78f7d75e5 switch coda get_d... |
136 |
if (idx < 0 || idx >= MAX_CODADEVS) { |
6d6bd94f4 fs/coda: use __fu... |
137 138 |
pr_warn("%s: Bad minor number ", __func__); |
1da177e4c Linux-2.6.12-rc2 |
139 140 141 142 |
return -1; } return idx; |
78f7d75e5 switch coda get_d... |
143 |
Ebadf: |
6d6bd94f4 fs/coda: use __fu... |
144 145 |
pr_warn("%s: Bad file ", __func__); |
78f7d75e5 switch coda get_d... |
146 |
return -1; |
1da177e4c Linux-2.6.12-rc2 |
147 148 149 150 |
} static int coda_fill_super(struct super_block *sb, void *data, int silent) { |
a1b0aa876 coda: remove stru... |
151 |
struct inode *root = NULL; |
da47c19e5 Coda: replace BKL... |
152 |
struct venus_comm *vc; |
1da177e4c Linux-2.6.12-rc2 |
153 |
struct CodaFid fid; |
a1b0aa876 coda: remove stru... |
154 |
int error; |
1da177e4c Linux-2.6.12-rc2 |
155 |
int idx; |
9fd973e08 coda: Restrict co... |
156 157 |
if (task_active_pid_ns(current) != &init_pid_ns) return -EINVAL; |
1da177e4c Linux-2.6.12-rc2 |
158 159 160 161 162 163 |
idx = get_device_index((struct coda_mount_data *) data); /* Ignore errors in data, for backward compatibility */ if(idx == -1) idx = 0; |
6d6bd94f4 fs/coda: use __fu... |
164 165 |
pr_info("%s: device index: %i ", __func__, idx); |
1da177e4c Linux-2.6.12-rc2 |
166 167 |
vc = &coda_comms[idx]; |
da47c19e5 Coda: replace BKL... |
168 |
mutex_lock(&vc->vc_mutex); |
f7cc02b87 Coda: push BKL re... |
169 |
|
1da177e4c Linux-2.6.12-rc2 |
170 |
if (!vc->vc_inuse) { |
6d6bd94f4 fs/coda: use __fu... |
171 172 |
pr_warn("%s: No pseudo device ", __func__); |
f7cc02b87 Coda: push BKL re... |
173 174 |
error = -EINVAL; goto unlock_out; |
1da177e4c Linux-2.6.12-rc2 |
175 |
} |
f7cc02b87 Coda: push BKL re... |
176 |
if (vc->vc_sb) { |
6d6bd94f4 fs/coda: use __fu... |
177 178 |
pr_warn("%s: Device already mounted ", __func__); |
f7cc02b87 Coda: push BKL re... |
179 180 |
error = -EBUSY; goto unlock_out; |
1da177e4c Linux-2.6.12-rc2 |
181 |
} |
b4caecd48 fs: introduce f_o... |
182 |
error = bdi_setup_and_register(&vc->bdi, "coda"); |
5163d9007 coda: add bdi bac... |
183 |
if (error) |
f7cc02b87 Coda: push BKL re... |
184 |
goto unlock_out; |
5163d9007 coda: add bdi bac... |
185 |
|
1da177e4c Linux-2.6.12-rc2 |
186 |
vc->vc_sb = sb; |
da47c19e5 Coda: replace BKL... |
187 |
mutex_unlock(&vc->vc_mutex); |
1da177e4c Linux-2.6.12-rc2 |
188 |
|
a1b0aa876 coda: remove stru... |
189 |
sb->s_fs_info = vc; |
fac1f0e34 coda: coda doesn'... |
190 191 192 193 194 |
sb->s_flags |= MS_NOATIME; sb->s_blocksize = 4096; /* XXXXX what do we put here?? */ sb->s_blocksize_bits = 12; sb->s_magic = CODA_SUPER_MAGIC; sb->s_op = &coda_super_operations; |
9501e4c48 switch coda |
195 |
sb->s_d_op = &coda_dentry_operations; |
5163d9007 coda: add bdi bac... |
196 |
sb->s_bdi = &vc->bdi; |
1da177e4c Linux-2.6.12-rc2 |
197 198 199 200 |
/* get root fid from Venus: this needs the root inode */ error = venus_rootfid(sb, &fid); if ( error ) { |
6d6bd94f4 fs/coda: use __fu... |
201 202 203 |
pr_warn("%s: coda_get_rootfid failed with %d ", __func__, error); |
1da177e4c Linux-2.6.12-rc2 |
204 205 |
goto error; } |
6d6bd94f4 fs/coda: use __fu... |
206 207 |
pr_info("%s: rootfid is %s ", __func__, coda_f2s(&fid)); |
1da177e4c Linux-2.6.12-rc2 |
208 209 |
/* make root inode */ |
f4947fbce coda: switch coda... |
210 211 212 |
root = coda_cnode_make(&fid, sb); if (IS_ERR(root)) { error = PTR_ERR(root); |
d9b4b3195 fs/coda: replace ... |
213 214 215 |
pr_warn("Failure of coda_cnode_make for root: error %d ", error); |
f4947fbce coda: switch coda... |
216 |
goto error; |
1da177e4c Linux-2.6.12-rc2 |
217 |
} |
6d6bd94f4 fs/coda: use __fu... |
218 219 220 |
pr_info("%s: rootinode is %ld dev %s ", __func__, root->i_ino, root->i_sb->s_id); |
48fde701a switch open-coded... |
221 |
sb->s_root = d_make_root(root); |
f7cc02b87 Coda: push BKL re... |
222 223 |
if (!sb->s_root) { error = -EINVAL; |
1da177e4c Linux-2.6.12-rc2 |
224 |
goto error; |
f7cc02b87 Coda: push BKL re... |
225 |
} |
db7192221 BKL: Explicitly a... |
226 |
return 0; |
1da177e4c Linux-2.6.12-rc2 |
227 |
|
f7cc02b87 Coda: push BKL re... |
228 |
error: |
da47c19e5 Coda: replace BKL... |
229 |
mutex_lock(&vc->vc_mutex); |
f7cc02b87 Coda: push BKL re... |
230 231 232 233 |
bdi_destroy(&vc->bdi); vc->vc_sb = NULL; sb->s_fs_info = NULL; unlock_out: |
da47c19e5 Coda: replace BKL... |
234 |
mutex_unlock(&vc->vc_mutex); |
f7cc02b87 Coda: push BKL re... |
235 |
return error; |
1da177e4c Linux-2.6.12-rc2 |
236 237 238 239 |
} static void coda_put_super(struct super_block *sb) { |
da47c19e5 Coda: replace BKL... |
240 241 242 243 |
struct venus_comm *vcp = coda_vcp(sb); mutex_lock(&vcp->vc_mutex); bdi_destroy(&vcp->bdi); vcp->vc_sb = NULL; |
a1b0aa876 coda: remove stru... |
244 |
sb->s_fs_info = NULL; |
da47c19e5 Coda: replace BKL... |
245 |
mutex_unlock(&vcp->vc_mutex); |
1da177e4c Linux-2.6.12-rc2 |
246 |
|
f38cfb256 fs/coda: logging ... |
247 248 |
pr_info("Bye bye. "); |
1da177e4c Linux-2.6.12-rc2 |
249 |
} |
b57922d97 convert remaining... |
250 |
static void coda_evict_inode(struct inode *inode) |
1da177e4c Linux-2.6.12-rc2 |
251 |
{ |
91b0abe36 mm + fs: store sh... |
252 |
truncate_inode_pages_final(&inode->i_data); |
dbd5768f8 vfs: Rename end_w... |
253 |
clear_inode(inode); |
1da177e4c Linux-2.6.12-rc2 |
254 255 256 257 258 |
coda_cache_clear_inode(inode); } int coda_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) { |
2b0143b5c VFS: normal files... |
259 |
int err = coda_revalidate_inode(d_inode(dentry)); |
1da177e4c Linux-2.6.12-rc2 |
260 |
if (!err) |
2b0143b5c VFS: normal files... |
261 |
generic_fillattr(d_inode(dentry), stat); |
1da177e4c Linux-2.6.12-rc2 |
262 263 264 265 266 |
return err; } int coda_setattr(struct dentry *de, struct iattr *iattr) { |
2b0143b5c VFS: normal files... |
267 |
struct inode *inode = d_inode(de); |
1da177e4c Linux-2.6.12-rc2 |
268 269 |
struct coda_vattr vattr; int error; |
1da177e4c Linux-2.6.12-rc2 |
270 |
memset(&vattr, 0, sizeof(vattr)); |
02027d42c fs: Replace CURRE... |
271 |
inode->i_ctime = current_time(inode); |
1da177e4c Linux-2.6.12-rc2 |
272 273 274 275 276 |
coda_iattr_to_vattr(iattr, &vattr); vattr.va_type = C_VNON; /* cannot set type */ /* Venus is responsible for truncating the container-file!!! */ error = venus_setattr(inode->i_sb, coda_i2f(inode), &vattr); |
f7cc02b87 Coda: push BKL re... |
277 |
if (!error) { |
1da177e4c Linux-2.6.12-rc2 |
278 279 280 |
coda_vattr_to_iattr(inode, &vattr); coda_cache_clear_inode(inode); } |
1da177e4c Linux-2.6.12-rc2 |
281 282 |
return error; } |
754661f14 [PATCH] mark stru... |
283 |
const struct inode_operations coda_file_inode_operations = { |
1da177e4c Linux-2.6.12-rc2 |
284 285 286 287 |
.permission = coda_permission, .getattr = coda_getattr, .setattr = coda_setattr, }; |
726c33422 [PATCH] VFS: Perm... |
288 |
static int coda_statfs(struct dentry *dentry, struct kstatfs *buf) |
1da177e4c Linux-2.6.12-rc2 |
289 290 291 |
{ int error; |
726c33422 [PATCH] VFS: Perm... |
292 |
error = venus_statfs(dentry, buf); |
1da177e4c Linux-2.6.12-rc2 |
293 |
|
1da177e4c Linux-2.6.12-rc2 |
294 295 296 297 298 299 300 301 302 303 304 |
if (error) { /* fake something like AFS does */ buf->f_blocks = 9000000; buf->f_bfree = 9000000; buf->f_bavail = 9000000; buf->f_files = 9000000; buf->f_ffree = 9000000; } /* and fill in the rest */ buf->f_type = CODA_SUPER_MAGIC; |
fac1f0e34 coda: coda doesn'... |
305 |
buf->f_bsize = 4096; |
1da177e4c Linux-2.6.12-rc2 |
306 307 308 309 310 311 |
buf->f_namelen = CODA_MAXNAMLEN; return 0; } /* init_coda: used by filesystems.c to register coda */ |
3c26ff6e4 convert get_sb_no... |
312 313 |
static struct dentry *coda_mount(struct file_system_type *fs_type, int flags, const char *dev_name, void *data) |
1da177e4c Linux-2.6.12-rc2 |
314 |
{ |
3c26ff6e4 convert get_sb_no... |
315 |
return mount_nodev(fs_type, flags, data, coda_fill_super); |
1da177e4c Linux-2.6.12-rc2 |
316 317 318 319 320 |
} struct file_system_type coda_fs_type = { .owner = THIS_MODULE, .name = "coda", |
3c26ff6e4 convert get_sb_no... |
321 |
.mount = coda_mount, |
1da177e4c Linux-2.6.12-rc2 |
322 323 324 |
.kill_sb = kill_anon_super, .fs_flags = FS_BINARY_MOUNTDATA, }; |
7f78e0351 fs: Limit sys_mou... |
325 |
MODULE_ALIAS_FS("coda"); |
1da177e4c Linux-2.6.12-rc2 |
326 |