2 * Copyright (c) 2002 Red Hat, Inc. All rights reserved.
4 * This software may be freely redistributed under the terms of the
5 * GNU General Public License.
7 * You should have received a copy of the GNU General Public License
8 * along with this program; if not, write to the Free Software
9 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
11 * Authors: David Woodhouse <dwmw2@cambridge.redhat.com>
12 * David Howells <dhowells@redhat.com>
16 #include <linux/kernel.h>
17 #include <linux/module.h>
18 #include <linux/init.h>
19 #include <linux/slab.h>
21 #include <linux/pagemap.h>
24 struct afs_iget_data {
26 struct afs_volume *volume; /* volume on which resides */
30 * map the AFS file status to the inode member variables
32 static int afs_inode_map_status(struct afs_vnode *vnode, struct key *key)
34 struct inode *inode = AFS_VNODE_TO_I(vnode);
36 _debug("FS: ft=%d lk=%d sz=%Zu ver=%Lu mod=%hu",
40 vnode->status.data_version,
43 switch (vnode->status.type) {
45 inode->i_mode = S_IFREG | vnode->status.mode;
46 inode->i_op = &afs_file_inode_operations;
47 inode->i_fop = &afs_file_operations;
50 inode->i_mode = S_IFDIR | vnode->status.mode;
51 inode->i_op = &afs_dir_inode_operations;
52 inode->i_fop = &afs_dir_file_operations;
54 case AFS_FTYPE_SYMLINK:
55 inode->i_mode = S_IFLNK | vnode->status.mode;
56 inode->i_op = &page_symlink_inode_operations;
59 printk("kAFS: AFS vnode with undefined type\n");
63 inode->i_nlink = vnode->status.nlink;
64 inode->i_uid = vnode->status.owner;
66 inode->i_size = vnode->status.size;
67 inode->i_ctime.tv_sec = vnode->status.mtime_server;
68 inode->i_ctime.tv_nsec = 0;
69 inode->i_atime = inode->i_mtime = inode->i_ctime;
71 inode->i_version = vnode->fid.unique;
72 inode->i_mapping->a_ops = &afs_fs_aops;
74 /* check to see whether a symbolic link is really a mountpoint */
75 if (vnode->status.type == AFS_FTYPE_SYMLINK) {
76 afs_mntpt_check_symlink(vnode, key);
78 if (test_bit(AFS_VNODE_MOUNTPOINT, &vnode->flags)) {
79 inode->i_mode = S_IFDIR | vnode->status.mode;
80 inode->i_op = &afs_mntpt_inode_operations;
81 inode->i_fop = &afs_mntpt_file_operations;
91 static int afs_iget5_test(struct inode *inode, void *opaque)
93 struct afs_iget_data *data = opaque;
95 return inode->i_ino == data->fid.vnode &&
96 inode->i_version == data->fid.unique;
100 * iget5() inode initialiser
102 static int afs_iget5_set(struct inode *inode, void *opaque)
104 struct afs_iget_data *data = opaque;
105 struct afs_vnode *vnode = AFS_FS_I(inode);
107 inode->i_ino = data->fid.vnode;
108 inode->i_version = data->fid.unique;
109 vnode->fid = data->fid;
110 vnode->volume = data->volume;
118 inline struct inode *afs_iget(struct super_block *sb, struct key *key,
121 struct afs_iget_data data = { .fid = *fid };
122 struct afs_super_info *as;
123 struct afs_vnode *vnode;
127 _enter(",{%u,%u,%u},,", fid->vid, fid->vnode, fid->unique);
130 data.volume = as->volume;
132 inode = iget5_locked(sb, fid->vnode, afs_iget5_test, afs_iget5_set,
135 _leave(" = -ENOMEM");
136 return ERR_PTR(-ENOMEM);
139 _debug("GOT INODE %p { vl=%x vn=%x, u=%x }",
140 inode, fid->vid, fid->vnode, fid->unique);
142 vnode = AFS_FS_I(inode);
144 /* deal with an existing inode */
145 if (!(inode->i_state & I_NEW)) {
146 _leave(" = %p", inode);
150 #ifdef AFS_CACHING_SUPPORT
151 /* set up caching before reading the status, as fetch-status reads the
152 * first page of symlinks to see if they're really mntpts */
153 cachefs_acquire_cookie(vnode->volume->cache,
159 /* okay... it's a new inode */
160 set_bit(AFS_VNODE_CB_BROKEN, &vnode->flags);
161 ret = afs_vnode_fetch_status(vnode, NULL, key);
164 ret = afs_inode_map_status(vnode, key);
169 inode->i_flags |= S_NOATIME;
170 unlock_new_inode(inode);
171 _leave(" = %p [CB { v=%u t=%u }]", inode, vnode->cb_version, vnode->cb_type);
176 make_bad_inode(inode);
177 unlock_new_inode(inode);
180 _leave(" = %d [bad]", ret);
185 * read the attributes of an inode
187 int afs_inode_getattr(struct vfsmount *mnt, struct dentry *dentry,
192 inode = dentry->d_inode;
194 _enter("{ ino=%lu v=%lu }", inode->i_ino, inode->i_version);
196 generic_fillattr(inode, stat);
203 void afs_clear_inode(struct inode *inode)
205 struct afs_permits *permits;
206 struct afs_vnode *vnode;
208 vnode = AFS_FS_I(inode);
210 _enter("ino=%lu { vn=%08x v=%u x=%u t=%u }",
217 _debug("CLEAR INODE %p", inode);
219 ASSERTCMP(inode->i_ino, ==, vnode->fid.vnode);
221 afs_give_up_callback(vnode);
224 spin_lock(&vnode->server->fs_lock);
225 rb_erase(&vnode->server_rb, &vnode->server->fs_vnodes);
226 spin_unlock(&vnode->server->fs_lock);
227 afs_put_server(vnode->server);
228 vnode->server = NULL;
231 ASSERT(!vnode->cb_promised);
233 #ifdef AFS_CACHING_SUPPORT
234 cachefs_relinquish_cookie(vnode->cache, 0);
238 mutex_lock(&vnode->permits_lock);
239 permits = vnode->permits;
240 rcu_assign_pointer(vnode->permits, NULL);
241 mutex_unlock(&vnode->permits_lock);
243 call_rcu(&permits->rcu, afs_zap_permits);