blob: dd8931345a8df8b3bcb5c887ea878cec4c23eea8 [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>
Jeff Laytona01179e2017-12-11 06:35:11 -050024#include <linux/iversion.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include "internal.h"
David Howellsa38a7552019-05-14 12:29:11 +010026#include "afs_fs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
David Howellsd3e3b7ea2017-07-06 15:50:27 +010028static const struct inode_operations afs_symlink_inode_operations = {
29 .get_link = page_get_link,
30 .listxattr = afs_listxattr,
31};
32
David Howellsb134d682019-04-25 14:26:52 +010033static noinline void dump_vnode(struct afs_vnode *vnode, struct afs_vnode *parent_vnode)
34{
35 static unsigned long once_only;
36
37 pr_warn("kAFS: AFS vnode with undefined type %u\n",
38 vnode->status.type);
39 pr_warn("kAFS: A=%d m=%o s=%llx v=%llx\n",
40 vnode->status.abort_code,
41 vnode->status.mode,
42 vnode->status.size,
43 vnode->status.data_version);
44 pr_warn("kAFS: vnode %llx:%llx:%x\n",
45 vnode->fid.vid,
46 vnode->fid.vnode,
47 vnode->fid.unique);
48 if (parent_vnode)
49 pr_warn("kAFS: dir %llx:%llx:%x\n",
50 parent_vnode->fid.vid,
51 parent_vnode->fid.vnode,
52 parent_vnode->fid.unique);
53
54 if (!test_and_set_bit(0, &once_only))
55 dump_stack();
56}
57
Linus Torvalds1da177e2005-04-16 15:20:36 -070058/*
David Howellsdd9fbcb2018-04-06 14:17:24 +010059 * Initialise an inode from the vnode status.
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 */
David Howellsb134d682019-04-25 14:26:52 +010061static int afs_inode_init_from_status(struct afs_vnode *vnode, struct key *key,
David Howellsa58823a2019-05-09 15:16:10 +010062 struct afs_cb_interest *cbi,
63 struct afs_vnode *parent_vnode,
64 struct afs_status_cb *scb)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065{
David Howellsa58823a2019-05-09 15:16:10 +010066 struct afs_cb_interest *old_cbi = NULL;
67 struct afs_file_status *status = &scb->status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 struct inode *inode = AFS_VNODE_TO_I(vnode);
David Howellsa58823a2019-05-09 15:16:10 +010069 struct timespec64 t;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
David Howells260a9802007-04-26 15:59:35 -070071 _debug("FS: ft=%d lk=%d sz=%llu ver=%Lu mod=%hu",
David Howellsa58823a2019-05-09 15:16:10 +010072 status->type,
73 status->nlink,
74 (unsigned long long) status->size,
75 status->data_version,
76 status->mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
David Howellsa58823a2019-05-09 15:16:10 +010078 write_seqlock(&vnode->cb_lock);
David Howellsc435ee32017-11-02 15:27:49 +000079
David Howellsa58823a2019-05-09 15:16:10 +010080 vnode->status = *status;
David Howellsdd9fbcb2018-04-06 14:17:24 +010081
David Howellsa58823a2019-05-09 15:16:10 +010082 t = status->mtime_client;
83 inode->i_ctime = t;
84 inode->i_mtime = t;
85 inode->i_atime = t;
86 inode->i_uid = make_kuid(&init_user_ns, status->owner);
87 inode->i_gid = make_kgid(&init_user_ns, status->group);
88 set_nlink(&vnode->vfs_inode, status->nlink);
89
90 switch (status->type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 case AFS_FTYPE_FILE:
David Howellsa58823a2019-05-09 15:16:10 +010092 inode->i_mode = S_IFREG | status->mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 inode->i_op = &afs_file_inode_operations;
David Howells00d3b7a2007-04-26 15:57:07 -070094 inode->i_fop = &afs_file_operations;
David Howellsf3ddee82018-04-06 14:17:25 +010095 inode->i_mapping->a_ops = &afs_fs_aops;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 break;
97 case AFS_FTYPE_DIR:
David Howellsa58823a2019-05-09 15:16:10 +010098 inode->i_mode = S_IFDIR | status->mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 inode->i_op = &afs_dir_inode_operations;
100 inode->i_fop = &afs_dir_file_operations;
David Howellsf3ddee82018-04-06 14:17:25 +0100101 inode->i_mapping->a_ops = &afs_dir_aops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 break;
103 case AFS_FTYPE_SYMLINK:
David Howells944c74f2017-03-16 16:27:45 +0000104 /* Symlinks with a mode of 0644 are actually mountpoints. */
David Howellsa58823a2019-05-09 15:16:10 +0100105 if ((status->mode & 0777) == 0644) {
David Howells944c74f2017-03-16 16:27:45 +0000106 inode->i_flags |= S_AUTOMOUNT;
107
David Howells944c74f2017-03-16 16:27:45 +0000108 set_bit(AFS_VNODE_MOUNTPOINT, &vnode->flags);
David Howells944c74f2017-03-16 16:27:45 +0000109
110 inode->i_mode = S_IFDIR | 0555;
111 inode->i_op = &afs_mntpt_inode_operations;
112 inode->i_fop = &afs_mntpt_file_operations;
David Howellsf3ddee82018-04-06 14:17:25 +0100113 inode->i_mapping->a_ops = &afs_fs_aops;
David Howells944c74f2017-03-16 16:27:45 +0000114 } else {
David Howellsa58823a2019-05-09 15:16:10 +0100115 inode->i_mode = S_IFLNK | status->mode;
David Howellsd3e3b7ea2017-07-06 15:50:27 +0100116 inode->i_op = &afs_symlink_inode_operations;
David Howellsf3ddee82018-04-06 14:17:25 +0100117 inode->i_mapping->a_ops = &afs_fs_aops;
David Howells944c74f2017-03-16 16:27:45 +0000118 }
Al Viro21fc61c2015-11-17 01:07:57 -0500119 inode_nohighmem(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 break;
121 default:
David Howellsb134d682019-04-25 14:26:52 +0100122 dump_vnode(vnode, parent_vnode);
David Howellsa58823a2019-05-09 15:16:10 +0100123 write_sequnlock(&vnode->cb_lock);
David Howells160cb952018-10-20 00:57:56 +0100124 return afs_protocol_error(NULL, -EBADMSG, afs_eproto_file_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 }
126
Marc Dionnec0abbb52019-04-25 12:04:37 -0300127 /*
128 * Estimate 512 bytes blocks used, rounded up to nearest 1K
129 * for consistency with other AFS clients.
130 */
131 inode->i_blocks = ((i_size_read(inode) + 1023) >> 10) << 1;
David Howellsa58823a2019-05-09 15:16:10 +0100132 i_size_write(&vnode->vfs_inode, status->size);
David Howellsc435ee32017-11-02 15:27:49 +0000133
David Howellsa58823a2019-05-09 15:16:10 +0100134 vnode->invalid_before = status->data_version;
135 inode_set_iversion_raw(&vnode->vfs_inode, status->data_version);
136
137 if (!scb->have_cb) {
138 /* it's a symlink we just created (the fileserver
139 * didn't give us a callback) */
David Howellsa58823a2019-05-09 15:16:10 +0100140 vnode->cb_expires_at = ktime_get_real_seconds();
141 } else {
David Howellsa58823a2019-05-09 15:16:10 +0100142 vnode->cb_expires_at = scb->callback.expires_at;
David Howellsf6424042019-05-13 16:14:32 +0100143 old_cbi = rcu_dereference_protected(vnode->cb_interest,
144 lockdep_is_held(&vnode->cb_lock.lock));
David Howellsa58823a2019-05-09 15:16:10 +0100145 if (cbi != old_cbi)
David Howellsf6424042019-05-13 16:14:32 +0100146 rcu_assign_pointer(vnode->cb_interest, afs_get_cb_interest(cbi));
David Howellsa58823a2019-05-09 15:16:10 +0100147 else
148 old_cbi = NULL;
149 set_bit(AFS_VNODE_CB_PROMISED, &vnode->flags);
150 }
151
152 write_sequnlock(&vnode->cb_lock);
153 afs_put_cb_interest(afs_v2net(vnode), old_cbi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 return 0;
David Howellsec268152007-04-26 15:49:28 -0700155}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157/*
David Howellsa58823a2019-05-09 15:16:10 +0100158 * Update the core inode struct from a returned status record.
159 */
160static void afs_apply_status(struct afs_fs_cursor *fc,
161 struct afs_vnode *vnode,
162 struct afs_status_cb *scb,
163 const afs_dataversion_t *expected_version)
164{
165 struct afs_file_status *status = &scb->status;
166 struct timespec64 t;
167 umode_t mode;
168 bool data_changed = false;
169
170 BUG_ON(test_bit(AFS_VNODE_UNSET, &vnode->flags));
171
172 if (status->type != vnode->status.type) {
173 pr_warning("Vnode %llx:%llx:%x changed type %u to %u\n",
174 vnode->fid.vid,
175 vnode->fid.vnode,
176 vnode->fid.unique,
177 status->type, vnode->status.type);
178 afs_protocol_error(NULL, -EBADMSG, afs_eproto_bad_status);
179 return;
180 }
181
182 if (status->nlink != vnode->status.nlink)
183 set_nlink(&vnode->vfs_inode, status->nlink);
184
185 if (status->owner != vnode->status.owner)
186 vnode->vfs_inode.i_uid = make_kuid(&init_user_ns, status->owner);
187
188 if (status->group != vnode->status.group)
189 vnode->vfs_inode.i_gid = make_kgid(&init_user_ns, status->group);
190
191 if (status->mode != vnode->status.mode) {
192 mode = vnode->vfs_inode.i_mode;
193 mode &= ~S_IALLUGO;
194 mode |= status->mode;
195 WRITE_ONCE(vnode->vfs_inode.i_mode, mode);
196 }
197
198 t = status->mtime_client;
199 vnode->vfs_inode.i_ctime = t;
200 vnode->vfs_inode.i_mtime = t;
201 vnode->vfs_inode.i_atime = t;
202
203 if (vnode->status.data_version != status->data_version)
204 data_changed = true;
205
206 vnode->status = *status;
207
208 if (expected_version &&
209 *expected_version != status->data_version) {
David Howells3647e422019-06-19 10:56:03 +0100210 if (test_bit(AFS_VNODE_CB_PROMISED, &vnode->flags))
211 pr_warn("kAFS: vnode modified {%llx:%llu} %llx->%llx %s\n",
212 vnode->fid.vid, vnode->fid.vnode,
213 (unsigned long long)*expected_version,
214 (unsigned long long)status->data_version,
215 fc->type ? fc->type->name : "???");
216
David Howellsa58823a2019-05-09 15:16:10 +0100217 vnode->invalid_before = status->data_version;
218 if (vnode->status.type == AFS_FTYPE_DIR) {
219 if (test_and_clear_bit(AFS_VNODE_DIR_VALID, &vnode->flags))
220 afs_stat_v(vnode, n_inval);
221 } else {
222 set_bit(AFS_VNODE_ZAP_DATA, &vnode->flags);
223 }
224 } else if (vnode->status.type == AFS_FTYPE_DIR) {
225 /* Expected directory change is handled elsewhere so
226 * that we can locally edit the directory and save on a
227 * download.
228 */
229 if (test_bit(AFS_VNODE_DIR_VALID, &vnode->flags))
230 data_changed = false;
231 }
232
233 if (data_changed) {
234 inode_set_iversion_raw(&vnode->vfs_inode, status->data_version);
235 i_size_write(&vnode->vfs_inode, status->size);
236 }
237}
238
239/*
240 * Apply a callback to a vnode.
241 */
242static void afs_apply_callback(struct afs_fs_cursor *fc,
243 struct afs_vnode *vnode,
244 struct afs_status_cb *scb,
245 unsigned int cb_break)
246{
247 struct afs_cb_interest *old;
248 struct afs_callback *cb = &scb->callback;
249
250 if (!afs_cb_is_broken(cb_break, vnode, fc->cbi)) {
David Howellsa58823a2019-05-09 15:16:10 +0100251 vnode->cb_expires_at = cb->expires_at;
David Howellsf6424042019-05-13 16:14:32 +0100252 old = rcu_dereference_protected(vnode->cb_interest,
253 lockdep_is_held(&vnode->cb_lock.lock));
David Howellsa58823a2019-05-09 15:16:10 +0100254 if (old != fc->cbi) {
David Howellsf6424042019-05-13 16:14:32 +0100255 rcu_assign_pointer(vnode->cb_interest, afs_get_cb_interest(fc->cbi));
David Howellsa58823a2019-05-09 15:16:10 +0100256 afs_put_cb_interest(afs_v2net(vnode), old);
257 }
258 set_bit(AFS_VNODE_CB_PROMISED, &vnode->flags);
259 }
260}
261
262/*
263 * Apply the received status and callback to an inode all in the same critical
264 * section to avoid races with afs_validate().
265 */
266void afs_vnode_commit_status(struct afs_fs_cursor *fc,
267 struct afs_vnode *vnode,
268 unsigned int cb_break,
269 const afs_dataversion_t *expected_version,
270 struct afs_status_cb *scb)
271{
272 if (fc->ac.error != 0)
273 return;
274
275 write_seqlock(&vnode->cb_lock);
276
David Howellsa38a7552019-05-14 12:29:11 +0100277 if (scb->have_error) {
278 if (scb->status.abort_code == VNOVNODE) {
279 set_bit(AFS_VNODE_DELETED, &vnode->flags);
280 clear_nlink(&vnode->vfs_inode);
281 __afs_break_callback(vnode);
282 }
283 } else {
284 if (scb->have_status)
285 afs_apply_status(fc, vnode, scb, expected_version);
286 if (scb->have_cb)
287 afs_apply_callback(fc, vnode, scb, cb_break);
288 }
David Howellsa58823a2019-05-09 15:16:10 +0100289
290 write_sequnlock(&vnode->cb_lock);
291
David Howellsa38a7552019-05-14 12:29:11 +0100292 if (fc->ac.error == 0 && scb->have_status)
David Howellsa58823a2019-05-09 15:16:10 +0100293 afs_cache_permit(vnode, fc->key, cb_break, scb);
294}
295
296/*
David Howellsd2ddc772017-11-02 15:27:50 +0000297 * Fetch file status from the volume.
298 */
David Howellsa58823a2019-05-09 15:16:10 +0100299int afs_fetch_status(struct afs_vnode *vnode, struct key *key, bool is_new,
300 afs_access_t *_caller_access)
David Howellsd2ddc772017-11-02 15:27:50 +0000301{
David Howellsa58823a2019-05-09 15:16:10 +0100302 struct afs_status_cb *scb;
David Howellsd2ddc772017-11-02 15:27:50 +0000303 struct afs_fs_cursor fc;
304 int ret;
305
David Howells3b6492d2018-10-20 00:57:57 +0100306 _enter("%s,{%llx:%llu.%u,S=%lx}",
David Howellsd2ddc772017-11-02 15:27:50 +0000307 vnode->volume->name,
308 vnode->fid.vid, vnode->fid.vnode, vnode->fid.unique,
309 vnode->flags);
310
David Howellsa58823a2019-05-09 15:16:10 +0100311 scb = kzalloc(sizeof(struct afs_status_cb), GFP_KERNEL);
312 if (!scb)
313 return -ENOMEM;
314
David Howellsd2ddc772017-11-02 15:27:50 +0000315 ret = -ERESTARTSYS;
David Howells20b83912019-05-08 16:16:31 +0100316 if (afs_begin_vnode_operation(&fc, vnode, key, true)) {
David Howellsa58823a2019-05-09 15:16:10 +0100317 afs_dataversion_t data_version = vnode->status.data_version;
318
David Howellsd2ddc772017-11-02 15:27:50 +0000319 while (afs_select_fileserver(&fc)) {
David Howells68251f02018-05-12 22:31:33 +0100320 fc.cb_break = afs_calc_vnode_cb_break(vnode);
David Howellsa58823a2019-05-09 15:16:10 +0100321 afs_fs_fetch_file_status(&fc, scb, NULL);
David Howellsd2ddc772017-11-02 15:27:50 +0000322 }
323
David Howellsa58823a2019-05-09 15:16:10 +0100324 if (fc.error) {
325 /* Do nothing. */
326 } else if (is_new) {
327 ret = afs_inode_init_from_status(vnode, key, fc.cbi,
328 NULL, scb);
329 fc.error = ret;
330 if (ret == 0)
331 afs_cache_permit(vnode, key, fc.cb_break, scb);
332 } else {
333 afs_vnode_commit_status(&fc, vnode, fc.cb_break,
334 &data_version, scb);
335 }
336 afs_check_for_remote_deletion(&fc, vnode);
David Howellsd2ddc772017-11-02 15:27:50 +0000337 ret = afs_end_vnode_operation(&fc);
338 }
339
David Howellsa58823a2019-05-09 15:16:10 +0100340 if (ret == 0 && _caller_access)
341 *_caller_access = scb->status.caller_access;
342 kfree(scb);
David Howellsd2ddc772017-11-02 15:27:50 +0000343 _leave(" = %d", ret);
344 return ret;
345}
346
347/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 * iget5() comparator
349 */
David Howellsc435ee32017-11-02 15:27:49 +0000350int afs_iget5_test(struct inode *inode, void *opaque)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351{
David Howellsb8359152019-05-14 12:23:43 +0100352 struct afs_iget_data *iget_data = opaque;
David Howells3b6492d2018-10-20 00:57:57 +0100353 struct afs_vnode *vnode = AFS_FS_I(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
David Howellsb8359152019-05-14 12:23:43 +0100355 return memcmp(&vnode->fid, &iget_data->fid, sizeof(iget_data->fid)) == 0;
David Howellsec268152007-04-26 15:49:28 -0700356}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358/*
wangleibec5eb62010-08-11 09:38:04 +0100359 * iget5() comparator for inode created by autocell operations
360 *
361 * These pseudo inodes don't match anything.
362 */
David Howells4d673da2018-02-06 06:26:30 +0000363static int afs_iget5_pseudo_dir_test(struct inode *inode, void *opaque)
wangleibec5eb62010-08-11 09:38:04 +0100364{
365 return 0;
366}
367
368/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 * iget5() inode initialiser
370 */
371static int afs_iget5_set(struct inode *inode, void *opaque)
372{
David Howellsb8359152019-05-14 12:23:43 +0100373 struct afs_iget_data *iget_data = opaque;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 struct afs_vnode *vnode = AFS_FS_I(inode);
375
David Howellsb8359152019-05-14 12:23:43 +0100376 vnode->fid = iget_data->fid;
377 vnode->volume = iget_data->volume;
378 vnode->cb_v_break = iget_data->cb_v_break;
379 vnode->cb_s_break = iget_data->cb_s_break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380
David Howells3b6492d2018-10-20 00:57:57 +0100381 /* YFS supports 96-bit vnode IDs, but Linux only supports
382 * 64-bit inode numbers.
383 */
David Howellsb8359152019-05-14 12:23:43 +0100384 inode->i_ino = iget_data->fid.vnode;
385 inode->i_generation = iget_data->fid.unique;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 return 0;
David Howellsec268152007-04-26 15:49:28 -0700387}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389/*
David Howells4d673da2018-02-06 06:26:30 +0000390 * Create an inode for a dynamic root directory or an autocell dynamic
391 * automount dir.
wangleibec5eb62010-08-11 09:38:04 +0100392 */
David Howells4d673da2018-02-06 06:26:30 +0000393struct inode *afs_iget_pseudo_dir(struct super_block *sb, bool root)
wangleibec5eb62010-08-11 09:38:04 +0100394{
wangleibec5eb62010-08-11 09:38:04 +0100395 struct afs_super_info *as;
396 struct afs_vnode *vnode;
wangleibec5eb62010-08-11 09:38:04 +0100397 struct inode *inode;
398 static atomic_t afs_autocell_ino;
399
David Howellsb8359152019-05-14 12:23:43 +0100400 struct afs_iget_data iget_data = {
401 .cb_v_break = 0,
402 .cb_s_break = 0,
403 };
404
David Howells4d673da2018-02-06 06:26:30 +0000405 _enter("");
wangleibec5eb62010-08-11 09:38:04 +0100406
wangleibec5eb62010-08-11 09:38:04 +0100407 as = sb->s_fs_info;
David Howells4d673da2018-02-06 06:26:30 +0000408 if (as->volume) {
David Howellsb8359152019-05-14 12:23:43 +0100409 iget_data.volume = as->volume;
410 iget_data.fid.vid = as->volume->vid;
David Howells4d673da2018-02-06 06:26:30 +0000411 }
412 if (root) {
David Howellsb8359152019-05-14 12:23:43 +0100413 iget_data.fid.vnode = 1;
414 iget_data.fid.unique = 1;
David Howells4d673da2018-02-06 06:26:30 +0000415 } else {
David Howellsb8359152019-05-14 12:23:43 +0100416 iget_data.fid.vnode = atomic_inc_return(&afs_autocell_ino);
417 iget_data.fid.unique = 0;
David Howells4d673da2018-02-06 06:26:30 +0000418 }
wangleibec5eb62010-08-11 09:38:04 +0100419
David Howellsb8359152019-05-14 12:23:43 +0100420 inode = iget5_locked(sb, iget_data.fid.vnode,
David Howells4d673da2018-02-06 06:26:30 +0000421 afs_iget5_pseudo_dir_test, afs_iget5_set,
David Howellsb8359152019-05-14 12:23:43 +0100422 &iget_data);
wangleibec5eb62010-08-11 09:38:04 +0100423 if (!inode) {
424 _leave(" = -ENOMEM");
425 return ERR_PTR(-ENOMEM);
426 }
427
David Howells3b6492d2018-10-20 00:57:57 +0100428 _debug("GOT INODE %p { ino=%lu, vl=%llx, vn=%llx, u=%x }",
David Howellsb8359152019-05-14 12:23:43 +0100429 inode, inode->i_ino, iget_data.fid.vid, iget_data.fid.vnode,
430 iget_data.fid.unique);
wangleibec5eb62010-08-11 09:38:04 +0100431
432 vnode = AFS_FS_I(inode);
433
434 /* there shouldn't be an existing inode */
435 BUG_ON(!(inode->i_state & I_NEW));
436
437 inode->i_size = 0;
438 inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO;
David Howells4d673da2018-02-06 06:26:30 +0000439 if (root) {
440 inode->i_op = &afs_dynroot_inode_operations;
441 inode->i_fop = &afs_dynroot_file_operations;
442 } else {
443 inode->i_op = &afs_autocell_inode_operations;
444 }
Miklos Szeredibfe86842011-10-28 14:13:29 +0200445 set_nlink(inode, 2);
Eric W. Biedermana0a53862012-02-07 16:20:48 -0800446 inode->i_uid = GLOBAL_ROOT_UID;
447 inode->i_gid = GLOBAL_ROOT_GID;
Arnd Bergmannba25b812019-04-13 08:37:36 +0100448 inode->i_ctime = inode->i_atime = inode->i_mtime = current_time(inode);
wangleibec5eb62010-08-11 09:38:04 +0100449 inode->i_blocks = 0;
Jeff Laytona01179e2017-12-11 06:35:11 -0500450 inode_set_iversion_raw(inode, 0);
wangleibec5eb62010-08-11 09:38:04 +0100451 inode->i_generation = 0;
452
453 set_bit(AFS_VNODE_PSEUDODIR, &vnode->flags);
David Howells4d673da2018-02-06 06:26:30 +0000454 if (!root) {
455 set_bit(AFS_VNODE_MOUNTPOINT, &vnode->flags);
456 inode->i_flags |= S_AUTOMOUNT;
457 }
458
459 inode->i_flags |= S_NOATIME;
wangleibec5eb62010-08-11 09:38:04 +0100460 unlock_new_inode(inode);
461 _leave(" = %p", inode);
462 return inode;
463}
464
465/*
David Howells402cb8d2018-04-04 13:41:28 +0100466 * Get a cache cookie for an inode.
467 */
468static void afs_get_inode_cache(struct afs_vnode *vnode)
469{
470#ifdef CONFIG_AFS_FSCACHE
471 struct {
472 u32 vnode_id;
473 u32 unique;
474 u32 vnode_id_ext[2]; /* Allow for a 96-bit key */
475 } __packed key;
476 struct afs_vnode_cache_aux aux;
477
David Howellsf3ddee82018-04-06 14:17:25 +0100478 if (vnode->status.type == AFS_FTYPE_DIR) {
479 vnode->cache = NULL;
480 return;
481 }
482
David Howells402cb8d2018-04-04 13:41:28 +0100483 key.vnode_id = vnode->fid.vnode;
484 key.unique = vnode->fid.unique;
David Howells3b6492d2018-10-20 00:57:57 +0100485 key.vnode_id_ext[0] = vnode->fid.vnode >> 32;
486 key.vnode_id_ext[1] = vnode->fid.vnode_hi;
David Howells402cb8d2018-04-04 13:41:28 +0100487 aux.data_version = vnode->status.data_version;
488
489 vnode->cache = fscache_acquire_cookie(vnode->volume->cache,
490 &afs_vnode_cache_index_def,
491 &key, sizeof(key),
492 &aux, sizeof(aux),
David Howellsee1235a2018-04-04 13:41:28 +0100493 vnode, vnode->status.size, true);
David Howells402cb8d2018-04-04 13:41:28 +0100494#endif
495}
496
497/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 * inode retrieval
499 */
David Howells260a9802007-04-26 15:59:35 -0700500struct inode *afs_iget(struct super_block *sb, struct key *key,
David Howellsb8359152019-05-14 12:23:43 +0100501 struct afs_iget_data *iget_data,
502 struct afs_status_cb *scb,
David Howellsa58823a2019-05-09 15:16:10 +0100503 struct afs_cb_interest *cbi,
David Howellsb134d682019-04-25 14:26:52 +0100504 struct afs_vnode *parent_vnode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 struct afs_super_info *as;
507 struct afs_vnode *vnode;
David Howellsb8359152019-05-14 12:23:43 +0100508 struct afs_fid *fid = &iget_data->fid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 struct inode *inode;
510 int ret;
511
David Howells3b6492d2018-10-20 00:57:57 +0100512 _enter(",{%llx:%llu.%u},,", fid->vid, fid->vnode, fid->unique);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513
514 as = sb->s_fs_info;
David Howellsb8359152019-05-14 12:23:43 +0100515 iget_data->volume = as->volume;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
517 inode = iget5_locked(sb, fid->vnode, afs_iget5_test, afs_iget5_set,
David Howellsb8359152019-05-14 12:23:43 +0100518 iget_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 if (!inode) {
520 _leave(" = -ENOMEM");
David Howells08e0e7c2007-04-26 15:55:03 -0700521 return ERR_PTR(-ENOMEM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 }
523
David Howells3b6492d2018-10-20 00:57:57 +0100524 _debug("GOT INODE %p { vl=%llx vn=%llx, u=%x }",
David Howells08e0e7c2007-04-26 15:55:03 -0700525 inode, fid->vid, fid->vnode, fid->unique);
526
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 vnode = AFS_FS_I(inode);
528
529 /* deal with an existing inode */
530 if (!(inode->i_state & I_NEW)) {
David Howells08e0e7c2007-04-26 15:55:03 -0700531 _leave(" = %p", inode);
532 return inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 }
534
David Howellsa58823a2019-05-09 15:16:10 +0100535 if (!scb) {
David Howells260a9802007-04-26 15:59:35 -0700536 /* it's a remotely extant inode */
David Howellsa58823a2019-05-09 15:16:10 +0100537 ret = afs_fetch_status(vnode, key, true, NULL);
David Howells260a9802007-04-26 15:59:35 -0700538 if (ret < 0)
539 goto bad_inode;
540 } else {
David Howellsa58823a2019-05-09 15:16:10 +0100541 ret = afs_inode_init_from_status(vnode, key, cbi, parent_vnode,
542 scb);
543 if (ret < 0)
544 goto bad_inode;
David Howells260a9802007-04-26 15:59:35 -0700545 }
546
David Howells5800db82018-04-06 14:17:24 +0100547 afs_get_inode_cache(vnode);
548
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 /* success */
David Howells260a9802007-04-26 15:59:35 -0700550 clear_bit(AFS_VNODE_UNSET, &vnode->flags);
David Howells08e0e7c2007-04-26 15:55:03 -0700551 inode->i_flags |= S_NOATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 unlock_new_inode(inode);
David Howells7c712452019-05-14 15:35:44 +0100553 _leave(" = %p", inode);
David Howells08e0e7c2007-04-26 15:55:03 -0700554 return inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
556 /* failure */
David Howellsec268152007-04-26 15:49:28 -0700557bad_inode:
David Howellsaa7fa242008-02-07 00:15:28 -0800558 iget_failed(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 _leave(" = %d [bad]", ret);
David Howells08e0e7c2007-04-26 15:55:03 -0700560 return ERR_PTR(ret);
David Howellsec268152007-04-26 15:49:28 -0700561}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563/*
David Howells416351f2007-05-09 02:33:45 -0700564 * mark the data attached to an inode as obsolete due to a write on the server
565 * - might also want to ditch all the outstanding writes and dirty pages
566 */
567void afs_zap_data(struct afs_vnode *vnode)
568{
David Howells3b6492d2018-10-20 00:57:57 +0100569 _enter("{%llx:%llu}", vnode->fid.vid, vnode->fid.vnode);
David Howells416351f2007-05-09 02:33:45 -0700570
David Howellsc1515992018-04-04 13:41:25 +0100571#ifdef CONFIG_AFS_FSCACHE
572 fscache_invalidate(vnode->cache);
573#endif
574
David Howells416351f2007-05-09 02:33:45 -0700575 /* nuke all the non-dirty pages that aren't locked, mapped or being
David Howells0f300ca2007-05-10 22:22:20 -0700576 * written back in a regular file and completely discard the pages in a
577 * directory or symlink */
578 if (S_ISREG(vnode->vfs_inode.i_mode))
579 invalidate_remote_inode(&vnode->vfs_inode);
580 else
581 invalidate_inode_pages2(vnode->vfs_inode.i_mapping);
David Howells416351f2007-05-09 02:33:45 -0700582}
583
584/*
David Howellsc925bd02019-05-09 14:31:11 +0100585 * Check the validity of a vnode/inode.
David Howells260a9802007-04-26 15:59:35 -0700586 */
David Howellsc925bd02019-05-09 14:31:11 +0100587bool afs_check_validity(struct afs_vnode *vnode)
David Howells260a9802007-04-26 15:59:35 -0700588{
David Howellsf6424042019-05-13 16:14:32 +0100589 struct afs_cb_interest *cbi;
590 struct afs_server *server;
591 struct afs_volume *volume = vnode->volume;
David Howellsc435ee32017-11-02 15:27:49 +0000592 time64_t now = ktime_get_real_seconds();
David Howells61c347b2019-05-09 14:15:11 +0100593 bool valid, need_clear = false;
David Howellsf6424042019-05-13 16:14:32 +0100594 unsigned int cb_break, cb_s_break, cb_v_break;
595 int seq = 0;
David Howells260a9802007-04-26 15:59:35 -0700596
David Howellsf6424042019-05-13 16:14:32 +0100597 do {
598 read_seqbegin_or_lock(&vnode->cb_lock, &seq);
599 cb_v_break = READ_ONCE(volume->cb_v_break);
600 cb_break = vnode->cb_break;
David Howellsc435ee32017-11-02 15:27:49 +0000601
David Howellsf6424042019-05-13 16:14:32 +0100602 if (test_bit(AFS_VNODE_CB_PROMISED, &vnode->flags)) {
603 cbi = rcu_dereference(vnode->cb_interest);
604 server = rcu_dereference(cbi->server);
605 cb_s_break = READ_ONCE(server->cb_s_break);
606
607 if (vnode->cb_s_break != cb_s_break ||
608 vnode->cb_v_break != cb_v_break) {
609 vnode->cb_s_break = cb_s_break;
610 vnode->cb_v_break = cb_v_break;
David Howells61c347b2019-05-09 14:15:11 +0100611 need_clear = true;
David Howellsf6424042019-05-13 16:14:32 +0100612 valid = false;
613 } else if (test_bit(AFS_VNODE_ZAP_DATA, &vnode->flags)) {
David Howells61c347b2019-05-09 14:15:11 +0100614 need_clear = true;
David Howellsf6424042019-05-13 16:14:32 +0100615 valid = false;
616 } else if (vnode->cb_expires_at - 10 <= now) {
David Howells61c347b2019-05-09 14:15:11 +0100617 need_clear = true;
David Howellsf6424042019-05-13 16:14:32 +0100618 valid = false;
619 } else {
620 valid = true;
621 }
622 } else if (test_bit(AFS_VNODE_DELETED, &vnode->flags)) {
David Howells68251f02018-05-12 22:31:33 +0100623 valid = true;
David Howellsf6424042019-05-13 16:14:32 +0100624 } else {
625 vnode->cb_v_break = cb_v_break;
626 valid = false;
David Howells260a9802007-04-26 15:59:35 -0700627 }
David Howells260a9802007-04-26 15:59:35 -0700628
David Howellsf6424042019-05-13 16:14:32 +0100629 } while (need_seqretry(&vnode->cb_lock, seq));
630
631 done_seqretry(&vnode->cb_lock, seq);
David Howells61c347b2019-05-09 14:15:11 +0100632
633 if (need_clear) {
634 write_seqlock(&vnode->cb_lock);
635 if (cb_break == vnode->cb_break)
636 __afs_break_callback(vnode);
637 write_sequnlock(&vnode->cb_lock);
638 valid = false;
639 }
640
David Howellsc925bd02019-05-09 14:31:11 +0100641 return valid;
642}
643
644/*
645 * validate a vnode/inode
646 * - there are several things we need to check
647 * - parent dir data changes (rm, rmdir, rename, mkdir, create, link,
648 * symlink)
649 * - parent dir metadata changed (security changes)
650 * - dentry data changed (write, truncate)
651 * - dentry metadata changed (security changes)
652 */
653int afs_validate(struct afs_vnode *vnode, struct key *key)
654{
655 bool valid;
656 int ret;
657
658 _enter("{v={%llx:%llu} fl=%lx},%x",
659 vnode->fid.vid, vnode->fid.vnode, vnode->flags,
660 key_serial(key));
661
David Howellsf6424042019-05-13 16:14:32 +0100662 rcu_read_lock();
David Howellsc925bd02019-05-09 14:31:11 +0100663 valid = afs_check_validity(vnode);
David Howellsf6424042019-05-13 16:14:32 +0100664 rcu_read_unlock();
David Howells440fbc32018-01-02 10:02:19 +0000665
666 if (test_bit(AFS_VNODE_DELETED, &vnode->flags))
667 clear_nlink(&vnode->vfs_inode);
668
David Howellsc435ee32017-11-02 15:27:49 +0000669 if (valid)
David Howells260a9802007-04-26 15:59:35 -0700670 goto valid;
671
David Howellsb61f7dc2018-04-27 20:46:22 +0100672 down_write(&vnode->validate_lock);
David Howells260a9802007-04-26 15:59:35 -0700673
674 /* if the promise has expired, we need to check the server again to get
675 * a new promise - note that if the (parent) directory's metadata was
676 * changed then the security may be different and we may no longer have
677 * access */
David Howellsc435ee32017-11-02 15:27:49 +0000678 if (!test_bit(AFS_VNODE_CB_PROMISED, &vnode->flags)) {
David Howells260a9802007-04-26 15:59:35 -0700679 _debug("not promised");
David Howellsa58823a2019-05-09 15:16:10 +0100680 ret = afs_fetch_status(vnode, key, false, NULL);
David Howellsc435ee32017-11-02 15:27:49 +0000681 if (ret < 0) {
682 if (ret == -ENOENT) {
683 set_bit(AFS_VNODE_DELETED, &vnode->flags);
684 ret = -ESTALE;
685 }
David Howells260a9802007-04-26 15:59:35 -0700686 goto error_unlock;
David Howellsc435ee32017-11-02 15:27:49 +0000687 }
David Howells260a9802007-04-26 15:59:35 -0700688 _debug("new promise [fl=%lx]", vnode->flags);
689 }
690
691 if (test_bit(AFS_VNODE_DELETED, &vnode->flags)) {
692 _debug("file already deleted");
693 ret = -ESTALE;
694 goto error_unlock;
695 }
696
697 /* if the vnode's data version number changed then its contents are
698 * different */
David Howells416351f2007-05-09 02:33:45 -0700699 if (test_and_clear_bit(AFS_VNODE_ZAP_DATA, &vnode->flags))
700 afs_zap_data(vnode);
David Howellsb61f7dc2018-04-27 20:46:22 +0100701 up_write(&vnode->validate_lock);
David Howells260a9802007-04-26 15:59:35 -0700702valid:
703 _leave(" = 0");
704 return 0;
705
706error_unlock:
David Howellsb61f7dc2018-04-27 20:46:22 +0100707 up_write(&vnode->validate_lock);
David Howells260a9802007-04-26 15:59:35 -0700708 _leave(" = %d", ret);
709 return ret;
710}
711
712/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 * read the attributes of an inode
714 */
David Howellsa528d352017-01-31 16:46:22 +0000715int afs_getattr(const struct path *path, struct kstat *stat,
716 u32 request_mask, unsigned int query_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717{
David Howellsa528d352017-01-31 16:46:22 +0000718 struct inode *inode = d_inode(path->dentry);
David Howellsc435ee32017-11-02 15:27:49 +0000719 struct afs_vnode *vnode = AFS_FS_I(inode);
720 int seq = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
David Howellsd6e43f72011-06-14 00:45:44 +0100722 _enter("{ ino=%lu v=%u }", inode->i_ino, inode->i_generation);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723
David Howellsc435ee32017-11-02 15:27:49 +0000724 do {
725 read_seqbegin_or_lock(&vnode->cb_lock, &seq);
726 generic_fillattr(inode, stat);
727 } while (need_seqretry(&vnode->cb_lock, seq));
728
729 done_seqretry(&vnode->cb_lock, seq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 return 0;
David Howellsec268152007-04-26 15:49:28 -0700731}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733/*
wangleibec5eb62010-08-11 09:38:04 +0100734 * discard an AFS inode
735 */
736int afs_drop_inode(struct inode *inode)
737{
738 _enter("");
739
740 if (test_bit(AFS_VNODE_PSEUDODIR, &AFS_FS_I(inode)->flags))
741 return generic_delete_inode(inode);
742 else
743 return generic_drop_inode(inode);
744}
745
746/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 * clear an AFS inode
748 */
Al Virob57922d2010-06-07 14:34:48 -0400749void afs_evict_inode(struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750{
David Howellsf6424042019-05-13 16:14:32 +0100751 struct afs_cb_interest *cbi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 struct afs_vnode *vnode;
753
754 vnode = AFS_FS_I(inode);
755
David Howells3b6492d2018-10-20 00:57:57 +0100756 _enter("{%llx:%llu.%d}",
David Howells260a9802007-04-26 15:59:35 -0700757 vnode->fid.vid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 vnode->fid.vnode,
David Howellsc435ee32017-11-02 15:27:49 +0000759 vnode->fid.unique);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
David Howells08e0e7c2007-04-26 15:55:03 -0700761 _debug("CLEAR INODE %p", inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
David Howells08e0e7c2007-04-26 15:55:03 -0700763 ASSERTCMP(inode->i_ino, ==, vnode->fid.vnode);
764
Johannes Weiner91b0abe2014-04-03 14:47:49 -0700765 truncate_inode_pages_final(&inode->i_data);
Jan Karadbd57682012-05-03 14:48:02 +0200766 clear_inode(inode);
Al Virob57922d2010-06-07 14:34:48 -0400767
David Howellsf6424042019-05-13 16:14:32 +0100768 write_seqlock(&vnode->cb_lock);
769 cbi = rcu_dereference_protected(vnode->cb_interest,
770 lockdep_is_held(&vnode->cb_lock.lock));
771 if (cbi) {
772 afs_put_cb_interest(afs_i2net(inode), cbi);
773 rcu_assign_pointer(vnode->cb_interest, NULL);
David Howells08e0e7c2007-04-26 15:55:03 -0700774 }
David Howellsf6424042019-05-13 16:14:32 +0100775 write_sequnlock(&vnode->cb_lock);
David Howells08e0e7c2007-04-26 15:55:03 -0700776
David Howells4343d002017-11-02 15:27:52 +0000777 while (!list_empty(&vnode->wb_keys)) {
778 struct afs_wb_key *wbk = list_entry(vnode->wb_keys.next,
779 struct afs_wb_key, vnode_link);
780 list_del(&wbk->vnode_link);
781 afs_put_wb_key(wbk);
782 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783
David Howells9b3f26c2009-04-03 16:42:41 +0100784#ifdef CONFIG_AFS_FSCACHE
David Howells402cb8d2018-04-04 13:41:28 +0100785 {
786 struct afs_vnode_cache_aux aux;
787
788 aux.data_version = vnode->status.data_version;
789 fscache_relinquish_cookie(vnode->cache, &aux,
790 test_bit(AFS_VNODE_DELETED, &vnode->flags));
791 vnode->cache = NULL;
792 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793#endif
794
David Howellsa1b879e2019-05-15 12:09:17 +0100795 afs_prune_wb_keys(vnode);
David Howellsfe342cf2018-04-09 21:12:31 +0100796 afs_put_permits(rcu_access_pointer(vnode->permit_cache));
David Howells79ddbfa2019-04-25 14:26:51 +0100797 key_put(vnode->silly_key);
798 vnode->silly_key = NULL;
David Howells59d49072019-01-09 17:23:54 +0000799 key_put(vnode->lock_key);
800 vnode->lock_key = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 _leave("");
David Howellsec268152007-04-26 15:49:28 -0700802}
David Howells31143d52007-05-09 02:33:46 -0700803
804/*
805 * set the attributes of an inode
806 */
807int afs_setattr(struct dentry *dentry, struct iattr *attr)
808{
David Howellsd2ddc772017-11-02 15:27:50 +0000809 struct afs_fs_cursor fc;
David Howellsa58823a2019-05-09 15:16:10 +0100810 struct afs_status_cb *scb;
David Howells2b0143b2015-03-17 22:25:59 +0000811 struct afs_vnode *vnode = AFS_FS_I(d_inode(dentry));
David Howells31143d52007-05-09 02:33:46 -0700812 struct key *key;
David Howellsa58823a2019-05-09 15:16:10 +0100813 int ret = -ENOMEM;
David Howells31143d52007-05-09 02:33:46 -0700814
David Howells3b6492d2018-10-20 00:57:57 +0100815 _enter("{%llx:%llu},{n=%pd},%x",
Al Viroa4555892014-10-21 20:11:25 -0400816 vnode->fid.vid, vnode->fid.vnode, dentry,
David Howells31143d52007-05-09 02:33:46 -0700817 attr->ia_valid);
818
819 if (!(attr->ia_valid & (ATTR_SIZE | ATTR_MODE | ATTR_UID | ATTR_GID |
820 ATTR_MTIME))) {
821 _leave(" = 0 [unsupported]");
822 return 0;
823 }
824
David Howellsa58823a2019-05-09 15:16:10 +0100825 scb = kzalloc(sizeof(struct afs_status_cb), GFP_KERNEL);
826 if (!scb)
827 goto error;
828
David Howells31143d52007-05-09 02:33:46 -0700829 /* flush any dirty data outstanding on a regular file */
David Howells4343d002017-11-02 15:27:52 +0000830 if (S_ISREG(vnode->vfs_inode.i_mode))
David Howells31143d52007-05-09 02:33:46 -0700831 filemap_write_and_wait(vnode->vfs_inode.i_mapping);
David Howells31143d52007-05-09 02:33:46 -0700832
833 if (attr->ia_valid & ATTR_FILE) {
David Howells215804a2017-11-02 15:27:52 +0000834 key = afs_file_key(attr->ia_file);
David Howells31143d52007-05-09 02:33:46 -0700835 } else {
836 key = afs_request_key(vnode->volume->cell);
837 if (IS_ERR(key)) {
838 ret = PTR_ERR(key);
David Howellsa58823a2019-05-09 15:16:10 +0100839 goto error_scb;
David Howells31143d52007-05-09 02:33:46 -0700840 }
841 }
842
David Howellsd2ddc772017-11-02 15:27:50 +0000843 ret = -ERESTARTSYS;
David Howells20b83912019-05-08 16:16:31 +0100844 if (afs_begin_vnode_operation(&fc, vnode, key, false)) {
David Howellsa58823a2019-05-09 15:16:10 +0100845 afs_dataversion_t data_version = vnode->status.data_version;
846
847 if (attr->ia_valid & ATTR_SIZE)
848 data_version++;
849
David Howellsd2ddc772017-11-02 15:27:50 +0000850 while (afs_select_fileserver(&fc)) {
David Howells68251f02018-05-12 22:31:33 +0100851 fc.cb_break = afs_calc_vnode_cb_break(vnode);
David Howellsa58823a2019-05-09 15:16:10 +0100852 afs_fs_setattr(&fc, attr, scb);
David Howellsd2ddc772017-11-02 15:27:50 +0000853 }
854
David Howellsa58823a2019-05-09 15:16:10 +0100855 afs_check_for_remote_deletion(&fc, vnode);
856 afs_vnode_commit_status(&fc, vnode, fc.cb_break,
857 &data_version, scb);
David Howellsd2ddc772017-11-02 15:27:50 +0000858 ret = afs_end_vnode_operation(&fc);
859 }
860
David Howells31143d52007-05-09 02:33:46 -0700861 if (!(attr->ia_valid & ATTR_FILE))
862 key_put(key);
863
David Howellsa58823a2019-05-09 15:16:10 +0100864error_scb:
865 kfree(scb);
David Howells31143d52007-05-09 02:33:46 -0700866error:
867 _leave(" = %d", ret);
868 return ret;
869}