1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
|
From 55eb2e7642e3428eaa1b2d833c0daa1d34b98324 Mon Sep 17 00:00:00 2001
From: Kotresh HR <khiremat@redhat.com>
Date: Thu, 8 Aug 2019 10:05:12 +0530
Subject: [PATCH 283/284] ctime: Fix ctime issue with utime family of syscalls
When atime|mtime is updated via utime family of syscalls,
ctime is not updated. This patch fixes the same.
Backport of:
> Patch: https://review.gluster.org/23177
> Change-Id: I7f86d8f8a1e06a332c3449b5bbdbf128c9690f25
> fixes: bz#1738786
> Signed-off-by: Kotresh HR <khiremat@redhat.com>
Change-Id: I7f86d8f8a1e06a332c3449b5bbdbf128c9690f25
BUG: 1743627
Signed-off-by: Kotresh HR <khiremat@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/179184
Tested-by: RHGS Build Bot <nigelb@redhat.com>
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
---
xlators/features/utime/src/utime-gen-fops-c.py | 13 +++-
xlators/storage/posix/src/posix-inode-fd-ops.c | 8 +--
xlators/storage/posix/src/posix-metadata.c | 96 ++++++++++++++------------
xlators/storage/posix/src/posix-metadata.h | 3 +-
4 files changed, 68 insertions(+), 52 deletions(-)
diff --git a/xlators/features/utime/src/utime-gen-fops-c.py b/xlators/features/utime/src/utime-gen-fops-c.py
index a8637ff..8730a51 100755
--- a/xlators/features/utime/src/utime-gen-fops-c.py
+++ b/xlators/features/utime/src/utime-gen-fops-c.py
@@ -82,7 +82,18 @@ gf_utime_@NAME@ (call_frame_t *frame, xlator_t *this,
@LONG_ARGS@)
{
gl_timespec_get(&frame->root->ctime);
- frame->root->flags |= MDATA_CTIME;
+
+ if (!valid) {
+ frame->root->flags |= MDATA_CTIME;
+ }
+
+ if (valid & (GF_SET_ATTR_UID | GF_SET_ATTR_GID)) {
+ frame->root->flags |= MDATA_CTIME;
+ }
+
+ if (valid & GF_SET_ATTR_MODE) {
+ frame->root->flags |= MDATA_CTIME;
+ }
STACK_WIND (frame, gf_utime_@NAME@_cbk, FIRST_CHILD(this),
FIRST_CHILD(this)->fops->@NAME@, @SHORT_ARGS@);
diff --git a/xlators/storage/posix/src/posix-inode-fd-ops.c b/xlators/storage/posix/src/posix-inode-fd-ops.c
index d22bbc2..e0ea85b 100644
--- a/xlators/storage/posix/src/posix-inode-fd-ops.c
+++ b/xlators/storage/posix/src/posix-inode-fd-ops.c
@@ -425,8 +425,8 @@ posix_setattr(call_frame_t *frame, xlator_t *this, loc_t *loc,
real_path);
goto out;
}
- posix_update_utime_in_mdata(this, real_path, -1, loc->inode, stbuf,
- valid);
+ posix_update_utime_in_mdata(this, real_path, -1, loc->inode,
+ &frame->root->ctime, stbuf, valid);
}
if (valid & GF_SET_ATTR_CTIME && !priv->ctime) {
@@ -652,8 +652,8 @@ posix_fsetattr(call_frame_t *frame, xlator_t *this, fd_t *fd,
fd);
goto out;
}
- posix_update_utime_in_mdata(this, NULL, pfd->fd, fd->inode, stbuf,
- valid);
+ posix_update_utime_in_mdata(this, NULL, pfd->fd, fd->inode,
+ &frame->root->ctime, stbuf, valid);
}
if (!valid) {
diff --git a/xlators/storage/posix/src/posix-metadata.c b/xlators/storage/posix/src/posix-metadata.c
index 5cbdc98..532daa2 100644
--- a/xlators/storage/posix/src/posix-metadata.c
+++ b/xlators/storage/posix/src/posix-metadata.c
@@ -432,8 +432,10 @@ out:
*/
static int
posix_set_mdata_xattr(xlator_t *this, const char *real_path, int fd,
- inode_t *inode, struct timespec *time, struct iatt *stbuf,
- posix_mdata_flag_t *flag, gf_boolean_t update_utime)
+ inode_t *inode, struct timespec *time,
+ struct timespec *u_atime, struct timespec *u_mtime,
+ struct iatt *stbuf, posix_mdata_flag_t *flag,
+ gf_boolean_t update_utime)
{
posix_mdata_t *mdata = NULL;
int ret = -1;
@@ -443,6 +445,10 @@ posix_set_mdata_xattr(xlator_t *this, const char *real_path, int fd,
GF_VALIDATE_OR_GOTO(this->name, inode, out);
GF_VALIDATE_OR_GOTO(this->name, time, out);
+ if (update_utime && (!u_atime || !u_mtime)) {
+ goto out;
+ }
+
LOCK(&inode->lock);
{
ret = __inode_ctx_get1(inode, this, (uint64_t *)&mdata);
@@ -506,32 +512,30 @@ posix_set_mdata_xattr(xlator_t *this, const char *real_path, int fd,
}
}
- /* Earlier, mdata was updated only if the existing time is less
- * than the time to be updated. This would fail the scenarios
- * where mtime can be set to any time using the syscall. Hence
- * just updating without comparison. But the ctime is not
- * allowed to changed to older date.
- */
-
- if (flag->ctime && posix_compare_timespec(time, &mdata->ctime) > 0) {
- mdata->ctime = *time;
- }
-
/* In distributed systems, there could be races with fops
* updating mtime/atime which could result in different
* mtime/atime for same file. So this makes sure, only the
* highest time is retained. If the mtime/atime update comes
* from the explicit utime syscall, it is allowed to set to
- * previous time
+ * previous or future time but the ctime is always set to
+ * current time.
*/
if (update_utime) {
+ if (flag->ctime &&
+ posix_compare_timespec(time, &mdata->ctime) > 0) {
+ mdata->ctime = *time;
+ }
if (flag->mtime) {
- mdata->mtime = *time;
+ mdata->mtime = *u_mtime;
}
if (flag->atime) {
- mdata->atime = *time;
+ mdata->atime = *u_atime;
}
} else {
+ if (flag->ctime &&
+ posix_compare_timespec(time, &mdata->ctime) > 0) {
+ mdata->ctime = *time;
+ }
if (flag->mtime &&
posix_compare_timespec(time, &mdata->mtime) > 0) {
mdata->mtime = *time;
@@ -584,15 +588,22 @@ out:
*/
void
posix_update_utime_in_mdata(xlator_t *this, const char *real_path, int fd,
- inode_t *inode, struct iatt *stbuf, int valid)
+ inode_t *inode, struct timespec *ctime,
+ struct iatt *stbuf, int valid)
{
int32_t ret = 0;
#if defined(HAVE_UTIMENSAT)
- struct timespec tv = {
+ struct timespec tv_atime = {
+ 0,
+ };
+ struct timespec tv_mtime = {
0,
};
#else
- struct timeval tv = {
+ struct timeval tv_atime = {
+ 0,
+ };
+ struct timeval tv_mtime = {
0,
};
#endif
@@ -611,35 +622,28 @@ posix_update_utime_in_mdata(xlator_t *this, const char *real_path, int fd,
*/
if (inode && priv->ctime) {
if ((valid & GF_SET_ATTR_ATIME) == GF_SET_ATTR_ATIME) {
- tv.tv_sec = stbuf->ia_atime;
- SET_TIMESPEC_NSEC_OR_TIMEVAL_USEC(tv, stbuf->ia_atime_nsec);
+ tv_atime.tv_sec = stbuf->ia_atime;
+ SET_TIMESPEC_NSEC_OR_TIMEVAL_USEC(tv_atime, stbuf->ia_atime_nsec);
- flag.ctime = 0;
- flag.mtime = 0;
+ flag.ctime = 1;
flag.atime = 1;
- ret = posix_set_mdata_xattr(this, real_path, -1, inode, &tv, NULL,
- &flag, _gf_true);
- if (ret) {
- gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_SETMDATA_FAILED,
- "posix set mdata atime failed on file:"
- " %s gfid:%s",
- real_path, uuid_utoa(inode->gfid));
- }
}
if ((valid & GF_SET_ATTR_MTIME) == GF_SET_ATTR_MTIME) {
- tv.tv_sec = stbuf->ia_mtime;
- SET_TIMESPEC_NSEC_OR_TIMEVAL_USEC(tv, stbuf->ia_mtime_nsec);
+ tv_mtime.tv_sec = stbuf->ia_mtime;
+ SET_TIMESPEC_NSEC_OR_TIMEVAL_USEC(tv_mtime, stbuf->ia_mtime_nsec);
- flag.ctime = 0;
+ flag.ctime = 1;
flag.mtime = 1;
- flag.atime = 0;
+ }
- ret = posix_set_mdata_xattr(this, real_path, -1, inode, &tv, NULL,
- &flag, _gf_true);
+ if (flag.mtime || flag.atime) {
+ ret = posix_set_mdata_xattr(this, real_path, -1, inode, ctime,
+ &tv_atime, &tv_mtime, NULL, &flag,
+ _gf_true);
if (ret) {
gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_SETMDATA_FAILED,
- "posix set mdata mtime failed on file:"
+ "posix set mdata atime failed on file:"
" %s gfid:%s",
real_path, uuid_utoa(inode->gfid));
}
@@ -702,8 +706,8 @@ posix_set_ctime(call_frame_t *frame, xlator_t *this, const char *real_path,
goto out;
}
ret = posix_set_mdata_xattr(this, real_path, fd, inode,
- &frame->root->ctime, stbuf, &flag,
- _gf_false);
+ &frame->root->ctime, NULL, NULL, stbuf,
+ &flag, _gf_false);
if (ret) {
gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_SETMDATA_FAILED,
"posix set mdata failed on file: %s gfid:%s", real_path,
@@ -733,8 +737,8 @@ posix_set_parent_ctime(call_frame_t *frame, xlator_t *this,
goto out;
}
ret = posix_set_mdata_xattr(this, real_path, fd, inode,
- &frame->root->ctime, stbuf, &flag,
- _gf_false);
+ &frame->root->ctime, NULL, NULL, stbuf,
+ &flag, _gf_false);
if (ret) {
gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_SETMDATA_FAILED,
"posix set mdata failed on file: %s gfid:%s", real_path,
@@ -792,8 +796,8 @@ posix_set_ctime_cfr(call_frame_t *frame, xlator_t *this,
flag_dup.atime = 0;
ret = posix_set_mdata_xattr(this, real_path_out, fd_out, inode_out,
- &frame->root->ctime, stbuf_out, &flag_dup,
- _gf_false);
+ &frame->root->ctime, NULL, NULL, stbuf_out,
+ &flag_dup, _gf_false);
if (ret) {
gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_SETMDATA_FAILED,
"posix set mdata failed on file: %s gfid:%s", real_path_out,
@@ -811,8 +815,8 @@ posix_set_ctime_cfr(call_frame_t *frame, xlator_t *this,
flag_dup.ctime = 0;
ret = posix_set_mdata_xattr(this, real_path_in, fd_out, inode_out,
- &frame->root->ctime, stbuf_out, &flag_dup,
- _gf_false);
+ &frame->root->ctime, NULL, NULL, stbuf_out,
+ &flag_dup, _gf_false);
if (ret) {
gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_SETMDATA_FAILED,
"posix set mdata failed on file: %s gfid:%s", real_path_in,
diff --git a/xlators/storage/posix/src/posix-metadata.h b/xlators/storage/posix/src/posix-metadata.h
index dc25e59..c176699 100644
--- a/xlators/storage/posix/src/posix-metadata.h
+++ b/xlators/storage/posix/src/posix-metadata.h
@@ -40,7 +40,8 @@ __posix_get_mdata_xattr(xlator_t *this, const char *real_path, int _fd,
inode_t *inode, struct iatt *stbuf);
void
posix_update_utime_in_mdata(xlator_t *this, const char *real_path, int fd,
- inode_t *inode, struct iatt *stbuf, int valid);
+ inode_t *inode, struct timespec *ctime,
+ struct iatt *stbuf, int valid);
void
posix_set_ctime(call_frame_t *frame, xlator_t *this, const char *real_path,
int fd, inode_t *inode, struct iatt *stbuf);
--
1.8.3.1
|