Skip to content

Commit da8d075

Browse files
committed
afs: Concoct ctimes
The in-kernel afs filesystem ignores ctime because the AFS fileserver protocol doesn't support ctimes. This, however, causes various xfstests to fail. Work around this by: (1) Setting ctime to attr->ia_ctime in afs_setattr(). (2) Not ignoring ATTR_MTIME_SET, ATTR_TIMES_SET and ATTR_TOUCH settings. (3) Setting the ctime from the server mtime when on the target file when creating a hard link to it. (4) Setting the ctime on directories from their revised mtimes when renaming/moving a file. Found by the generic/221 and generic/309 xfstests. Signed-off-by: David Howells <dhowells@redhat.com>
1 parent 3f4aa98 commit da8d075

4 files changed

Lines changed: 38 additions & 12 deletions

File tree

‎fs/afs/dir.c‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,7 @@ static void afs_vnode_new_inode(struct afs_operation *op)
12681268
static void afs_create_success(struct afs_operation *op)
12691269
{
12701270
_enter("op=%08x", op->debug_id);
1271+
op->ctime = op->file[0].scb.status.mtime_client;
12711272
afs_check_for_remote_deletion(op, op->file[0].vnode);
12721273
afs_vnode_commit_status(op, &op->file[0]);
12731274
afs_update_dentry_version(op, &op->file[0], op->dentry);
@@ -1325,6 +1326,7 @@ static int afs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
13251326

13261327
afs_op_set_vnode(op, 0, dvnode);
13271328
op->file[0].dv_delta = 1;
1329+
op->file[0].update_ctime = true;
13281330
op->dentry = dentry;
13291331
op->create.mode = S_IFDIR | mode;
13301332
op->create.reason = afs_edit_dir_for_mkdir;
@@ -1350,6 +1352,7 @@ static void afs_dir_remove_subdir(struct dentry *dentry)
13501352
static void afs_rmdir_success(struct afs_operation *op)
13511353
{
13521354
_enter("op=%08x", op->debug_id);
1355+
op->ctime = op->file[0].scb.status.mtime_client;
13531356
afs_check_for_remote_deletion(op, op->file[0].vnode);
13541357
afs_vnode_commit_status(op, &op->file[0]);
13551358
afs_update_dentry_version(op, &op->file[0], op->dentry);
@@ -1404,6 +1407,7 @@ static int afs_rmdir(struct inode *dir, struct dentry *dentry)
14041407

14051408
afs_op_set_vnode(op, 0, dvnode);
14061409
op->file[0].dv_delta = 1;
1410+
op->file[0].update_ctime = true;
14071411

14081412
op->dentry = dentry;
14091413
op->ops = &afs_rmdir_operation;
@@ -1479,6 +1483,7 @@ static void afs_dir_remove_link(struct afs_operation *op)
14791483
static void afs_unlink_success(struct afs_operation *op)
14801484
{
14811485
_enter("op=%08x", op->debug_id);
1486+
op->ctime = op->file[0].scb.status.mtime_client;
14821487
afs_check_for_remote_deletion(op, op->file[0].vnode);
14831488
afs_vnode_commit_status(op, &op->file[0]);
14841489
afs_vnode_commit_status(op, &op->file[1]);
@@ -1537,6 +1542,7 @@ static int afs_unlink(struct inode *dir, struct dentry *dentry)
15371542

15381543
afs_op_set_vnode(op, 0, dvnode);
15391544
op->file[0].dv_delta = 1;
1545+
op->file[0].update_ctime = true;
15401546

15411547
/* Try to make sure we have a callback promise on the victim. */
15421548
ret = afs_validate(vnode, op->key);
@@ -1561,6 +1567,7 @@ static int afs_unlink(struct inode *dir, struct dentry *dentry)
15611567
spin_unlock(&dentry->d_lock);
15621568

15631569
op->file[1].vnode = vnode;
1570+
op->file[1].update_ctime = true;
15641571
op->dentry = dentry;
15651572
op->ops = &afs_unlink_operation;
15661573
return afs_do_sync_operation(op);
@@ -1601,6 +1608,7 @@ static int afs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
16011608

16021609
afs_op_set_vnode(op, 0, dvnode);
16031610
op->file[0].dv_delta = 1;
1611+
op->file[0].update_ctime = true;
16041612

16051613
op->dentry = dentry;
16061614
op->create.mode = S_IFREG | mode;
@@ -1620,6 +1628,7 @@ static void afs_link_success(struct afs_operation *op)
16201628
struct afs_vnode_param *vp = &op->file[1];
16211629

16221630
_enter("op=%08x", op->debug_id);
1631+
op->ctime = dvp->scb.status.mtime_client;
16231632
afs_vnode_commit_status(op, dvp);
16241633
afs_vnode_commit_status(op, vp);
16251634
afs_update_dentry_version(op, dvp, op->dentry);
@@ -1672,6 +1681,8 @@ static int afs_link(struct dentry *from, struct inode *dir,
16721681
afs_op_set_vnode(op, 0, dvnode);
16731682
afs_op_set_vnode(op, 1, vnode);
16741683
op->file[0].dv_delta = 1;
1684+
op->file[0].update_ctime = true;
1685+
op->file[1].update_ctime = true;
16751686

16761687
op->dentry = dentry;
16771688
op->dentry_2 = from;
@@ -1740,9 +1751,12 @@ static void afs_rename_success(struct afs_operation *op)
17401751
{
17411752
_enter("op=%08x", op->debug_id);
17421753

1754+
op->ctime = op->file[0].scb.status.mtime_client;
17431755
afs_vnode_commit_status(op, &op->file[0]);
1744-
if (op->file[1].vnode != op->file[0].vnode)
1756+
if (op->file[1].vnode != op->file[0].vnode) {
1757+
op->ctime = op->file[1].scb.status.mtime_client;
17451758
afs_vnode_commit_status(op, &op->file[1]);
1759+
}
17461760
}
17471761

17481762
static void afs_rename_edit_dir(struct afs_operation *op)
@@ -1860,6 +1874,8 @@ static int afs_rename(struct inode *old_dir, struct dentry *old_dentry,
18601874
afs_op_set_vnode(op, 1, new_dvnode); /* May be same as orig_dvnode */
18611875
op->file[0].dv_delta = 1;
18621876
op->file[1].dv_delta = 1;
1877+
op->file[0].update_ctime = true;
1878+
op->file[1].update_ctime = true;
18631879

18641880
op->dentry = old_dentry;
18651881
op->dentry_2 = new_dentry;

‎fs/afs/inode.c‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ static void afs_apply_status(struct afs_operation *op,
165165
{
166166
struct afs_file_status *status = &vp->scb.status;
167167
struct afs_vnode *vnode = vp->vnode;
168+
struct inode *inode = &vnode->vfs_inode;
168169
struct timespec64 t;
169170
umode_t mode;
170171
bool data_changed = false;
@@ -187,25 +188,25 @@ static void afs_apply_status(struct afs_operation *op,
187188
}
188189

189190
if (status->nlink != vnode->status.nlink)
190-
set_nlink(&vnode->vfs_inode, status->nlink);
191+
set_nlink(inode, status->nlink);
191192

192193
if (status->owner != vnode->status.owner)
193-
vnode->vfs_inode.i_uid = make_kuid(&init_user_ns, status->owner);
194+
inode->i_uid = make_kuid(&init_user_ns, status->owner);
194195

195196
if (status->group != vnode->status.group)
196-
vnode->vfs_inode.i_gid = make_kgid(&init_user_ns, status->group);
197+
inode->i_gid = make_kgid(&init_user_ns, status->group);
197198

198199
if (status->mode != vnode->status.mode) {
199-
mode = vnode->vfs_inode.i_mode;
200+
mode = inode->i_mode;
200201
mode &= ~S_IALLUGO;
201202
mode |= status->mode;
202-
WRITE_ONCE(vnode->vfs_inode.i_mode, mode);
203+
WRITE_ONCE(inode->i_mode, mode);
203204
}
204205

205206
t = status->mtime_client;
206-
vnode->vfs_inode.i_ctime = t;
207-
vnode->vfs_inode.i_mtime = t;
208-
vnode->vfs_inode.i_atime = t;
207+
inode->i_mtime = t;
208+
if (vp->update_ctime)
209+
inode->i_ctime = op->ctime;
209210

210211
if (vnode->status.data_version != status->data_version)
211212
data_changed = true;
@@ -239,15 +240,18 @@ static void afs_apply_status(struct afs_operation *op,
239240
}
240241

241242
if (data_changed) {
242-
inode_set_iversion_raw(&vnode->vfs_inode, status->data_version);
243+
inode_set_iversion_raw(inode, status->data_version);
243244

244245
/* Only update the size if the data version jumped. If the
245246
* file is being modified locally, then we might have our own
246247
* idea of what the size should be that's not the same as
247248
* what's on the server.
248249
*/
249-
if (change_size)
250+
if (change_size) {
250251
afs_set_i_size(vnode, status->size);
252+
inode->i_ctime = t;
253+
inode->i_atime = t;
254+
}
251255
}
252256
}
253257

@@ -817,7 +821,8 @@ int afs_setattr(struct dentry *dentry, struct iattr *attr)
817821
attr->ia_valid);
818822

819823
if (!(attr->ia_valid & (ATTR_SIZE | ATTR_MODE | ATTR_UID | ATTR_GID |
820-
ATTR_MTIME))) {
824+
ATTR_MTIME | ATTR_MTIME_SET | ATTR_TIMES_SET |
825+
ATTR_TOUCH))) {
821826
_leave(" = 0 [unsupported]");
822827
return 0;
823828
}
@@ -837,6 +842,8 @@ int afs_setattr(struct dentry *dentry, struct iattr *attr)
837842

838843
if (attr->ia_valid & ATTR_SIZE)
839844
op->file[0].dv_delta = 1;
845+
op->ctime = attr->ia_ctime;
846+
op->file[0].update_ctime = 1;
840847

841848
op->ops = &afs_setattr_operation;
842849
return afs_do_sync_operation(op);

‎fs/afs/internal.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,7 @@ struct afs_vnode_param {
746746
u8 dv_delta; /* Expected change in data version */
747747
bool put_vnode; /* T if we have a ref on the vnode */
748748
bool need_io_lock; /* T if we need the I/O lock on this */
749+
bool update_ctime; /* Need to update the ctime */
749750
};
750751

751752
/*
@@ -766,6 +767,7 @@ struct afs_operation {
766767
struct dentry *dentry; /* Dentry to be altered */
767768
struct dentry *dentry_2; /* Second dentry to be altered */
768769
struct timespec64 mtime; /* Modification time to record */
770+
struct timespec64 ctime; /* Change time to set */
769771
short nr_files; /* Number of entries in file[], more_files */
770772
short error;
771773
unsigned int abort_code;

‎fs/afs/write.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ static void afs_store_data_success(struct afs_operation *op)
393393
{
394394
struct afs_vnode *vnode = op->file[0].vnode;
395395

396+
op->ctime = op->file[0].scb.status.mtime_client;
396397
afs_vnode_commit_status(op, &op->file[0]);
397398
if (op->error == 0) {
398399
afs_pages_written_back(vnode, op->store.first, op->store.last);

0 commit comments

Comments
 (0)