blob: 342316a9e3e0cb47449f7482cce9f5e5bdfe211a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 *
David Woodhouse44d1b982008-06-05 22:46:18 -070011 * Authors: David Woodhouse <dwmw2@infradead.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * David Howells <dhowells@redhat.com>
13 *
14 */
15
16#include <linux/kernel.h>
17#include <linux/module.h>
18#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/fs.h>
20#include <linux/pagemap.h>
Alexey Dobriyane8edc6e2007-05-21 01:22:52 +040021#include <linux/sched.h>
wangleibec5eb62010-08-11 09:38:04 +010022#include <linux/mount.h>
23#include <linux/namei.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include "internal.h"
25
26struct afs_iget_data {
27 struct afs_fid fid;
28 struct afs_volume *volume; /* volume on which resides */
29};
30
David Howellsd3e3b7ea2017-07-06 15:50:27 +010031static const struct inode_operations afs_symlink_inode_operations = {
32 .get_link = page_get_link,
33 .listxattr = afs_listxattr,
34};
35
Linus Torvalds1da177e2005-04-16 15:20:36 -070036/*
37 * map the AFS file status to the inode member variables
38 */
David Howells00d3b7a2007-04-26 15:57:07 -070039static int afs_inode_map_status(struct afs_vnode *vnode, struct key *key)
Linus Torvalds1da177e2005-04-16 15:20:36 -070040{
41 struct inode *inode = AFS_VNODE_TO_I(vnode);
42
David Howells260a9802007-04-26 15:59:35 -070043 _debug("FS: ft=%d lk=%d sz=%llu ver=%Lu mod=%hu",
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 vnode->status.type,
45 vnode->status.nlink,
David S. Millerba3e0e12007-04-26 16:06:22 -070046 (unsigned long long) vnode->status.size,
David Howells08e0e7c2007-04-26 15:55:03 -070047 vnode->status.data_version,
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 vnode->status.mode);
49
50 switch (vnode->status.type) {
51 case AFS_FTYPE_FILE:
52 inode->i_mode = S_IFREG | vnode->status.mode;
53 inode->i_op = &afs_file_inode_operations;
David Howells00d3b7a2007-04-26 15:57:07 -070054 inode->i_fop = &afs_file_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 break;
56 case AFS_FTYPE_DIR:
57 inode->i_mode = S_IFDIR | vnode->status.mode;
58 inode->i_op = &afs_dir_inode_operations;
59 inode->i_fop = &afs_dir_file_operations;
60 break;
61 case AFS_FTYPE_SYMLINK:
David Howells944c74f2017-03-16 16:27:45 +000062 /* Symlinks with a mode of 0644 are actually mountpoints. */
63 if ((vnode->status.mode & 0777) == 0644) {
64 inode->i_flags |= S_AUTOMOUNT;
65
66 spin_lock(&vnode->lock);
67 set_bit(AFS_VNODE_MOUNTPOINT, &vnode->flags);
68 spin_unlock(&vnode->lock);
69
70 inode->i_mode = S_IFDIR | 0555;
71 inode->i_op = &afs_mntpt_inode_operations;
72 inode->i_fop = &afs_mntpt_file_operations;
73 } else {
74 inode->i_mode = S_IFLNK | vnode->status.mode;
David Howellsd3e3b7ea2017-07-06 15:50:27 +010075 inode->i_op = &afs_symlink_inode_operations;
David Howells944c74f2017-03-16 16:27:45 +000076 }
Al Viro21fc61c2015-11-17 01:07:57 -050077 inode_nohighmem(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 break;
79 default:
80 printk("kAFS: AFS vnode with undefined type\n");
81 return -EBADMSG;
82 }
83
David Howells9b3f26c2009-04-03 16:42:41 +010084#ifdef CONFIG_AFS_FSCACHE
85 if (vnode->status.size != inode->i_size)
86 fscache_attr_changed(vnode->cache);
87#endif
88
Miklos Szeredibfe86842011-10-28 14:13:29 +020089 set_nlink(inode, vnode->status.nlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 inode->i_uid = vnode->status.owner;
Marc Dionne6186f072017-03-16 16:27:43 +000091 inode->i_gid = vnode->status.group;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 inode->i_size = vnode->status.size;
Marc Dionneab94f5d2017-03-16 16:27:47 +000093 inode->i_ctime.tv_sec = vnode->status.mtime_client;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 inode->i_ctime.tv_nsec = 0;
95 inode->i_atime = inode->i_mtime = inode->i_ctime;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 inode->i_blocks = 0;
David Howellsd6e43f72011-06-14 00:45:44 +010097 inode->i_generation = vnode->fid.unique;
98 inode->i_version = vnode->status.data_version;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 inode->i_mapping->a_ops = &afs_fs_aops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 return 0;
David Howellsec268152007-04-26 15:49:28 -0700101}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 * iget5() comparator
105 */
106static int afs_iget5_test(struct inode *inode, void *opaque)
107{
108 struct afs_iget_data *data = opaque;
109
110 return inode->i_ino == data->fid.vnode &&
David Howellsd6e43f72011-06-14 00:45:44 +0100111 inode->i_generation == data->fid.unique;
David Howellsec268152007-04-26 15:49:28 -0700112}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114/*
wangleibec5eb62010-08-11 09:38:04 +0100115 * iget5() comparator for inode created by autocell operations
116 *
117 * These pseudo inodes don't match anything.
118 */
119static int afs_iget5_autocell_test(struct inode *inode, void *opaque)
120{
121 return 0;
122}
123
124/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 * iget5() inode initialiser
126 */
127static int afs_iget5_set(struct inode *inode, void *opaque)
128{
129 struct afs_iget_data *data = opaque;
130 struct afs_vnode *vnode = AFS_FS_I(inode);
131
132 inode->i_ino = data->fid.vnode;
David Howellsd6e43f72011-06-14 00:45:44 +0100133 inode->i_generation = data->fid.unique;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 vnode->fid = data->fid;
135 vnode->volume = data->volume;
136
137 return 0;
David Howellsec268152007-04-26 15:49:28 -0700138}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140/*
wangleibec5eb62010-08-11 09:38:04 +0100141 * inode retrieval for autocell
142 */
143struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
144 int namesz, struct key *key)
145{
146 struct afs_iget_data data;
147 struct afs_super_info *as;
148 struct afs_vnode *vnode;
149 struct super_block *sb;
150 struct inode *inode;
151 static atomic_t afs_autocell_ino;
152
153 _enter("{%x:%u},%*.*s,",
154 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
155 namesz, namesz, dev_name ?: "");
156
157 sb = dir->i_sb;
158 as = sb->s_fs_info;
159 data.volume = as->volume;
160 data.fid.vid = as->volume->vid;
161 data.fid.unique = 0;
162 data.fid.vnode = 0;
163
164 inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
165 afs_iget5_autocell_test, afs_iget5_set,
166 &data);
167 if (!inode) {
168 _leave(" = -ENOMEM");
169 return ERR_PTR(-ENOMEM);
170 }
171
172 _debug("GOT INODE %p { ino=%lu, vl=%x, vn=%x, u=%x }",
173 inode, inode->i_ino, data.fid.vid, data.fid.vnode,
174 data.fid.unique);
175
176 vnode = AFS_FS_I(inode);
177
178 /* there shouldn't be an existing inode */
179 BUG_ON(!(inode->i_state & I_NEW));
180
181 inode->i_size = 0;
182 inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO;
183 inode->i_op = &afs_autocell_inode_operations;
Miklos Szeredibfe86842011-10-28 14:13:29 +0200184 set_nlink(inode, 2);
Eric W. Biedermana0a53862012-02-07 16:20:48 -0800185 inode->i_uid = GLOBAL_ROOT_UID;
186 inode->i_gid = GLOBAL_ROOT_GID;
wangleibec5eb62010-08-11 09:38:04 +0100187 inode->i_ctime.tv_sec = get_seconds();
188 inode->i_ctime.tv_nsec = 0;
189 inode->i_atime = inode->i_mtime = inode->i_ctime;
190 inode->i_blocks = 0;
191 inode->i_version = 0;
192 inode->i_generation = 0;
193
194 set_bit(AFS_VNODE_PSEUDODIR, &vnode->flags);
David Howellsd18610b2011-01-14 19:04:05 +0000195 set_bit(AFS_VNODE_MOUNTPOINT, &vnode->flags);
196 inode->i_flags |= S_AUTOMOUNT | S_NOATIME;
wangleibec5eb62010-08-11 09:38:04 +0100197 unlock_new_inode(inode);
198 _leave(" = %p", inode);
199 return inode;
200}
201
202/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 * inode retrieval
204 */
David Howells260a9802007-04-26 15:59:35 -0700205struct inode *afs_iget(struct super_block *sb, struct key *key,
206 struct afs_fid *fid, struct afs_file_status *status,
207 struct afs_callback *cb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208{
209 struct afs_iget_data data = { .fid = *fid };
210 struct afs_super_info *as;
211 struct afs_vnode *vnode;
212 struct inode *inode;
213 int ret;
214
David Howells416351f2007-05-09 02:33:45 -0700215 _enter(",{%x:%u.%u},,", fid->vid, fid->vnode, fid->unique);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
217 as = sb->s_fs_info;
218 data.volume = as->volume;
219
220 inode = iget5_locked(sb, fid->vnode, afs_iget5_test, afs_iget5_set,
221 &data);
222 if (!inode) {
223 _leave(" = -ENOMEM");
David Howells08e0e7c2007-04-26 15:55:03 -0700224 return ERR_PTR(-ENOMEM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 }
226
David Howells08e0e7c2007-04-26 15:55:03 -0700227 _debug("GOT INODE %p { vl=%x vn=%x, u=%x }",
228 inode, fid->vid, fid->vnode, fid->unique);
229
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 vnode = AFS_FS_I(inode);
231
232 /* deal with an existing inode */
233 if (!(inode->i_state & I_NEW)) {
David Howells08e0e7c2007-04-26 15:55:03 -0700234 _leave(" = %p", inode);
235 return inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 }
237
David Howells260a9802007-04-26 15:59:35 -0700238 if (!status) {
239 /* it's a remotely extant inode */
240 set_bit(AFS_VNODE_CB_BROKEN, &vnode->flags);
241 ret = afs_vnode_fetch_status(vnode, NULL, key);
242 if (ret < 0)
243 goto bad_inode;
244 } else {
245 /* it's an inode we just created */
246 memcpy(&vnode->status, status, sizeof(vnode->status));
247
248 if (!cb) {
249 /* it's a symlink we just created (the fileserver
250 * didn't give us a callback) */
251 vnode->cb_version = 0;
252 vnode->cb_expiry = 0;
253 vnode->cb_type = 0;
Tina Ruchandani56e71432017-03-16 16:27:46 +0000254 vnode->cb_expires = ktime_get_real_seconds();
David Howells260a9802007-04-26 15:59:35 -0700255 } else {
256 vnode->cb_version = cb->version;
257 vnode->cb_expiry = cb->expiry;
258 vnode->cb_type = cb->type;
Tina Ruchandani56e71432017-03-16 16:27:46 +0000259 vnode->cb_expires = vnode->cb_expiry +
260 ktime_get_real_seconds();
David Howells260a9802007-04-26 15:59:35 -0700261 }
262 }
263
David Howells9b3f26c2009-04-03 16:42:41 +0100264 /* set up caching before mapping the status, as map-status reads the
265 * first page of symlinks to see if they're really mountpoints */
266 inode->i_size = vnode->status.size;
267#ifdef CONFIG_AFS_FSCACHE
268 vnode->cache = fscache_acquire_cookie(vnode->volume->cache,
269 &afs_vnode_cache_index_def,
David Howells94d30ae2013-09-21 00:09:31 +0100270 vnode, true);
David Howells9b3f26c2009-04-03 16:42:41 +0100271#endif
272
David Howells00d3b7a2007-04-26 15:57:07 -0700273 ret = afs_inode_map_status(vnode, key);
David Howells08e0e7c2007-04-26 15:55:03 -0700274 if (ret < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 goto bad_inode;
276
277 /* success */
David Howells260a9802007-04-26 15:59:35 -0700278 clear_bit(AFS_VNODE_UNSET, &vnode->flags);
David Howells08e0e7c2007-04-26 15:55:03 -0700279 inode->i_flags |= S_NOATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 unlock_new_inode(inode);
David Howells08e0e7c2007-04-26 15:55:03 -0700281 _leave(" = %p [CB { v=%u t=%u }]", inode, vnode->cb_version, vnode->cb_type);
282 return inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
284 /* failure */
David Howellsec268152007-04-26 15:49:28 -0700285bad_inode:
David Howells9b3f26c2009-04-03 16:42:41 +0100286#ifdef CONFIG_AFS_FSCACHE
287 fscache_relinquish_cookie(vnode->cache, 0);
288 vnode->cache = NULL;
289#endif
David Howellsaa7fa242008-02-07 00:15:28 -0800290 iget_failed(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 _leave(" = %d [bad]", ret);
David Howells08e0e7c2007-04-26 15:55:03 -0700292 return ERR_PTR(ret);
David Howellsec268152007-04-26 15:49:28 -0700293}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295/*
David Howells416351f2007-05-09 02:33:45 -0700296 * mark the data attached to an inode as obsolete due to a write on the server
297 * - might also want to ditch all the outstanding writes and dirty pages
298 */
299void afs_zap_data(struct afs_vnode *vnode)
300{
David Howells0f300ca2007-05-10 22:22:20 -0700301 _enter("{%x:%u}", vnode->fid.vid, vnode->fid.vnode);
David Howells416351f2007-05-09 02:33:45 -0700302
303 /* nuke all the non-dirty pages that aren't locked, mapped or being
David Howells0f300ca2007-05-10 22:22:20 -0700304 * written back in a regular file and completely discard the pages in a
305 * directory or symlink */
306 if (S_ISREG(vnode->vfs_inode.i_mode))
307 invalidate_remote_inode(&vnode->vfs_inode);
308 else
309 invalidate_inode_pages2(vnode->vfs_inode.i_mapping);
David Howells416351f2007-05-09 02:33:45 -0700310}
311
312/*
David Howells260a9802007-04-26 15:59:35 -0700313 * validate a vnode/inode
314 * - there are several things we need to check
315 * - parent dir data changes (rm, rmdir, rename, mkdir, create, link,
316 * symlink)
317 * - parent dir metadata changed (security changes)
318 * - dentry data changed (write, truncate)
319 * - dentry metadata changed (security changes)
320 */
321int afs_validate(struct afs_vnode *vnode, struct key *key)
322{
323 int ret;
324
325 _enter("{v={%x:%u} fl=%lx},%x",
326 vnode->fid.vid, vnode->fid.vnode, vnode->flags,
327 key_serial(key));
328
329 if (vnode->cb_promised &&
330 !test_bit(AFS_VNODE_CB_BROKEN, &vnode->flags) &&
331 !test_bit(AFS_VNODE_MODIFIED, &vnode->flags) &&
332 !test_bit(AFS_VNODE_ZAP_DATA, &vnode->flags)) {
Tina Ruchandani56e71432017-03-16 16:27:46 +0000333 if (vnode->cb_expires < ktime_get_real_seconds() + 10) {
David Howells260a9802007-04-26 15:59:35 -0700334 _debug("callback expired");
335 set_bit(AFS_VNODE_CB_BROKEN, &vnode->flags);
336 } else {
337 goto valid;
338 }
339 }
340
341 if (test_bit(AFS_VNODE_DELETED, &vnode->flags))
342 goto valid;
343
344 mutex_lock(&vnode->validate_lock);
345
346 /* if the promise has expired, we need to check the server again to get
347 * a new promise - note that if the (parent) directory's metadata was
348 * changed then the security may be different and we may no longer have
349 * access */
350 if (!vnode->cb_promised ||
351 test_bit(AFS_VNODE_CB_BROKEN, &vnode->flags)) {
352 _debug("not promised");
353 ret = afs_vnode_fetch_status(vnode, NULL, key);
354 if (ret < 0)
355 goto error_unlock;
356 _debug("new promise [fl=%lx]", vnode->flags);
357 }
358
359 if (test_bit(AFS_VNODE_DELETED, &vnode->flags)) {
360 _debug("file already deleted");
361 ret = -ESTALE;
362 goto error_unlock;
363 }
364
365 /* if the vnode's data version number changed then its contents are
366 * different */
David Howells416351f2007-05-09 02:33:45 -0700367 if (test_and_clear_bit(AFS_VNODE_ZAP_DATA, &vnode->flags))
368 afs_zap_data(vnode);
David Howells260a9802007-04-26 15:59:35 -0700369
370 clear_bit(AFS_VNODE_MODIFIED, &vnode->flags);
371 mutex_unlock(&vnode->validate_lock);
372valid:
373 _leave(" = 0");
374 return 0;
375
376error_unlock:
377 mutex_unlock(&vnode->validate_lock);
378 _leave(" = %d", ret);
379 return ret;
380}
381
382/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 * read the attributes of an inode
384 */
David Howellsa528d352017-01-31 16:46:22 +0000385int afs_getattr(const struct path *path, struct kstat *stat,
386 u32 request_mask, unsigned int query_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387{
David Howellsa528d352017-01-31 16:46:22 +0000388 struct inode *inode = d_inode(path->dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
David Howellsd6e43f72011-06-14 00:45:44 +0100390 _enter("{ ino=%lu v=%u }", inode->i_ino, inode->i_generation);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 generic_fillattr(inode, stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 return 0;
David Howellsec268152007-04-26 15:49:28 -0700394}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396/*
wangleibec5eb62010-08-11 09:38:04 +0100397 * discard an AFS inode
398 */
399int afs_drop_inode(struct inode *inode)
400{
401 _enter("");
402
403 if (test_bit(AFS_VNODE_PSEUDODIR, &AFS_FS_I(inode)->flags))
404 return generic_delete_inode(inode);
405 else
406 return generic_drop_inode(inode);
407}
408
409/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 * clear an AFS inode
411 */
Al Virob57922d2010-06-07 14:34:48 -0400412void afs_evict_inode(struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413{
David Howells00d3b7a2007-04-26 15:57:07 -0700414 struct afs_permits *permits;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 struct afs_vnode *vnode;
416
417 vnode = AFS_FS_I(inode);
418
David Howells416351f2007-05-09 02:33:45 -0700419 _enter("{%x:%u.%d} v=%u x=%u t=%u }",
David Howells260a9802007-04-26 15:59:35 -0700420 vnode->fid.vid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 vnode->fid.vnode,
David Howells260a9802007-04-26 15:59:35 -0700422 vnode->fid.unique,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 vnode->cb_version,
424 vnode->cb_expiry,
David Howells08e0e7c2007-04-26 15:55:03 -0700425 vnode->cb_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
David Howells08e0e7c2007-04-26 15:55:03 -0700427 _debug("CLEAR INODE %p", inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
David Howells08e0e7c2007-04-26 15:55:03 -0700429 ASSERTCMP(inode->i_ino, ==, vnode->fid.vnode);
430
Johannes Weiner91b0abe2014-04-03 14:47:49 -0700431 truncate_inode_pages_final(&inode->i_data);
Jan Karadbd57682012-05-03 14:48:02 +0200432 clear_inode(inode);
Al Virob57922d2010-06-07 14:34:48 -0400433
David Howells08e0e7c2007-04-26 15:55:03 -0700434 afs_give_up_callback(vnode);
435
436 if (vnode->server) {
437 spin_lock(&vnode->server->fs_lock);
438 rb_erase(&vnode->server_rb, &vnode->server->fs_vnodes);
439 spin_unlock(&vnode->server->fs_lock);
440 afs_put_server(vnode->server);
441 vnode->server = NULL;
442 }
443
David Howells31143d52007-05-09 02:33:46 -0700444 ASSERT(list_empty(&vnode->writebacks));
David Howells08e0e7c2007-04-26 15:55:03 -0700445 ASSERT(!vnode->cb_promised);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
David Howells9b3f26c2009-04-03 16:42:41 +0100447#ifdef CONFIG_AFS_FSCACHE
448 fscache_relinquish_cookie(vnode->cache, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 vnode->cache = NULL;
450#endif
451
David Howells00d3b7a2007-04-26 15:57:07 -0700452 mutex_lock(&vnode->permits_lock);
453 permits = vnode->permits;
Andreea-Cristina Bernat1d7e4eb2017-03-16 16:27:45 +0000454 RCU_INIT_POINTER(vnode->permits, NULL);
David Howells00d3b7a2007-04-26 15:57:07 -0700455 mutex_unlock(&vnode->permits_lock);
456 if (permits)
457 call_rcu(&permits->rcu, afs_zap_permits);
458
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700460}
David Howells31143d52007-05-09 02:33:46 -0700461
462/*
463 * set the attributes of an inode
464 */
465int afs_setattr(struct dentry *dentry, struct iattr *attr)
466{
David Howells2b0143b2015-03-17 22:25:59 +0000467 struct afs_vnode *vnode = AFS_FS_I(d_inode(dentry));
David Howells31143d52007-05-09 02:33:46 -0700468 struct key *key;
469 int ret;
470
Al Viroa4555892014-10-21 20:11:25 -0400471 _enter("{%x:%u},{n=%pd},%x",
472 vnode->fid.vid, vnode->fid.vnode, dentry,
David Howells31143d52007-05-09 02:33:46 -0700473 attr->ia_valid);
474
475 if (!(attr->ia_valid & (ATTR_SIZE | ATTR_MODE | ATTR_UID | ATTR_GID |
476 ATTR_MTIME))) {
477 _leave(" = 0 [unsupported]");
478 return 0;
479 }
480
481 /* flush any dirty data outstanding on a regular file */
482 if (S_ISREG(vnode->vfs_inode.i_mode)) {
483 filemap_write_and_wait(vnode->vfs_inode.i_mapping);
484 afs_writeback_all(vnode);
485 }
486
487 if (attr->ia_valid & ATTR_FILE) {
488 key = attr->ia_file->private_data;
489 } else {
490 key = afs_request_key(vnode->volume->cell);
491 if (IS_ERR(key)) {
492 ret = PTR_ERR(key);
493 goto error;
494 }
495 }
496
497 ret = afs_vnode_setattr(vnode, key, attr);
498 if (!(attr->ia_valid & ATTR_FILE))
499 key_put(key);
500
501error:
502 _leave(" = %d", ret);
503 return ret;
504}