]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - fs/afs/inode.c
[AF_RXRPC]: Make the in-kernel AFS filesystem use AF_RXRPC.
[linux-2.6-omap-h63xx.git] / fs / afs / inode.c
1 /*
2  * Copyright (c) 2002 Red Hat, Inc. All rights reserved.
3  *
4  * This software may be freely redistributed under the terms of the
5  * GNU General Public License.
6  *
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.
10  *
11  * Authors: David Woodhouse <dwmw2@cambridge.redhat.com>
12  *          David Howells <dhowells@redhat.com>
13  *
14  */
15
16 #include <linux/kernel.h>
17 #include <linux/module.h>
18 #include <linux/init.h>
19 #include <linux/slab.h>
20 #include <linux/fs.h>
21 #include <linux/pagemap.h>
22 #include "internal.h"
23
24 struct afs_iget_data {
25         struct afs_fid          fid;
26         struct afs_volume       *volume;        /* volume on which resides */
27 };
28
29 /*
30  * map the AFS file status to the inode member variables
31  */
32 static int afs_inode_map_status(struct afs_vnode *vnode)
33 {
34         struct inode *inode = AFS_VNODE_TO_I(vnode);
35
36         _debug("FS: ft=%d lk=%d sz=%Zu ver=%Lu mod=%hu",
37                vnode->status.type,
38                vnode->status.nlink,
39                vnode->status.size,
40                vnode->status.data_version,
41                vnode->status.mode);
42
43         switch (vnode->status.type) {
44         case AFS_FTYPE_FILE:
45                 inode->i_mode   = S_IFREG | vnode->status.mode;
46                 inode->i_op     = &afs_file_inode_operations;
47                 inode->i_fop    = &generic_ro_fops;
48                 break;
49         case AFS_FTYPE_DIR:
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;
53                 break;
54         case AFS_FTYPE_SYMLINK:
55                 inode->i_mode   = S_IFLNK | vnode->status.mode;
56                 inode->i_op     = &page_symlink_inode_operations;
57                 break;
58         default:
59                 printk("kAFS: AFS vnode with undefined type\n");
60                 return -EBADMSG;
61         }
62
63         inode->i_nlink          = vnode->status.nlink;
64         inode->i_uid            = vnode->status.owner;
65         inode->i_gid            = 0;
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;
70         inode->i_blocks         = 0;
71         inode->i_version        = vnode->fid.unique;
72         inode->i_mapping->a_ops = &afs_fs_aops;
73
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);
77
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;
82                 }
83         }
84
85         return 0;
86 }
87
88 /*
89  * iget5() comparator
90  */
91 static int afs_iget5_test(struct inode *inode, void *opaque)
92 {
93         struct afs_iget_data *data = opaque;
94
95         return inode->i_ino == data->fid.vnode &&
96                 inode->i_version == data->fid.unique;
97 }
98
99 /*
100  * iget5() inode initialiser
101  */
102 static int afs_iget5_set(struct inode *inode, void *opaque)
103 {
104         struct afs_iget_data *data = opaque;
105         struct afs_vnode *vnode = AFS_FS_I(inode);
106
107         inode->i_ino = data->fid.vnode;
108         inode->i_version = data->fid.unique;
109         vnode->fid = data->fid;
110         vnode->volume = data->volume;
111
112         return 0;
113 }
114
115 /*
116  * inode retrieval
117  */
118 inline struct inode *afs_iget(struct super_block *sb, struct afs_fid *fid)
119 {
120         struct afs_iget_data data = { .fid = *fid };
121         struct afs_super_info *as;
122         struct afs_vnode *vnode;
123         struct inode *inode;
124         int ret;
125
126         _enter(",{%u,%u,%u},,", fid->vid, fid->vnode, fid->unique);
127
128         as = sb->s_fs_info;
129         data.volume = as->volume;
130
131         inode = iget5_locked(sb, fid->vnode, afs_iget5_test, afs_iget5_set,
132                              &data);
133         if (!inode) {
134                 _leave(" = -ENOMEM");
135                 return ERR_PTR(-ENOMEM);
136         }
137
138         _debug("GOT INODE %p { vl=%x vn=%x, u=%x }",
139                inode, fid->vid, fid->vnode, fid->unique);
140
141         vnode = AFS_FS_I(inode);
142
143         /* deal with an existing inode */
144         if (!(inode->i_state & I_NEW)) {
145                 _leave(" = %p", inode);
146                 return inode;
147         }
148
149 #ifdef AFS_CACHING_SUPPORT
150         /* set up caching before reading the status, as fetch-status reads the
151          * first page of symlinks to see if they're really mntpts */
152         cachefs_acquire_cookie(vnode->volume->cache,
153                                NULL,
154                                vnode,
155                                &vnode->cache);
156 #endif
157
158         /* okay... it's a new inode */
159         set_bit(AFS_VNODE_CB_BROKEN, &vnode->flags);
160         ret = afs_vnode_fetch_status(vnode);
161         if (ret < 0)
162                 goto bad_inode;
163         ret = afs_inode_map_status(vnode);
164         if (ret < 0)
165                 goto bad_inode;
166
167         /* success */
168         inode->i_flags |= S_NOATIME;
169         unlock_new_inode(inode);
170         _leave(" = %p [CB { v=%u t=%u }]", inode, vnode->cb_version, vnode->cb_type);
171         return inode;
172
173         /* failure */
174 bad_inode:
175         make_bad_inode(inode);
176         unlock_new_inode(inode);
177         iput(inode);
178
179         _leave(" = %d [bad]", ret);
180         return ERR_PTR(ret);
181 }
182
183 /*
184  * read the attributes of an inode
185  */
186 int afs_inode_getattr(struct vfsmount *mnt, struct dentry *dentry,
187                       struct kstat *stat)
188 {
189         struct inode *inode;
190
191         inode = dentry->d_inode;
192
193         _enter("{ ino=%lu v=%lu }", inode->i_ino, inode->i_version);
194
195         generic_fillattr(inode, stat);
196         return 0;
197 }
198
199 /*
200  * clear an AFS inode
201  */
202 void afs_clear_inode(struct inode *inode)
203 {
204         struct afs_vnode *vnode;
205
206         vnode = AFS_FS_I(inode);
207
208         _enter("ino=%lu { vn=%08x v=%u x=%u t=%u }",
209                inode->i_ino,
210                vnode->fid.vnode,
211                vnode->cb_version,
212                vnode->cb_expiry,
213                vnode->cb_type);
214
215         _debug("CLEAR INODE %p", inode);
216
217         ASSERTCMP(inode->i_ino, ==, vnode->fid.vnode);
218
219         afs_give_up_callback(vnode);
220
221         if (vnode->server) {
222                 spin_lock(&vnode->server->fs_lock);
223                 rb_erase(&vnode->server_rb, &vnode->server->fs_vnodes);
224                 spin_unlock(&vnode->server->fs_lock);
225                 afs_put_server(vnode->server);
226                 vnode->server = NULL;
227         }
228
229         ASSERT(!vnode->cb_promised);
230
231 #ifdef AFS_CACHING_SUPPORT
232         cachefs_relinquish_cookie(vnode->cache, 0);
233         vnode->cache = NULL;
234 #endif
235
236         _leave("");
237 }