summaryrefslogtreecommitdiff
path: root/0380-features-shard-Aggregate-size-block-count-in-iatt-be.patch
blob: 05915d9503a43e3c3e5223e8dbcd446538b7267a (plain)
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
From 2cf22e54c8424949607c4a20df84887b838b2702 Mon Sep 17 00:00:00 2001
From: Krutika Dhananjay <kdhananj@redhat.com>
Date: Fri, 15 May 2020 11:29:36 +0530
Subject: [PATCH 380/382] features/shard: Aggregate size, block-count in iatt
 before unwinding setxattr

Backport of:
> Upstream patch - https://review.gluster.org/c/glusterfs/+/24471
> Fixes: #1243
> Change-Id: I4da0eceb4235b91546df79270bcc0af8cd64e9ea
> Signed-off-by: Krutika Dhananjay <kdhananj@redhat.com>

Posix translator returns pre and postbufs in the dict in {F}SETXATTR fops.
These iatts are further cached at layers like md-cache.
Shard translator, in its current state, simply returns these values without
updating the aggregated file size and block-count.

This patch fixes this problem.

Change-Id: I4da0eceb4235b91546df79270bcc0af8cd64e9ea
BUG: 1823423
Signed-off-by: Krutika Dhananjay <kdhananj@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/201135
Tested-by: RHGS Build Bot <nigelb@redhat.com>
Reviewed-by: Xavi Hernandez Juan <xhernandez@redhat.com>
---
 tests/bugs/shard/issue-1243.t      |  31 ++++++
 xlators/features/shard/src/shard.c | 218 +++++++++++++++++++++++++++++++++----
 2 files changed, 225 insertions(+), 24 deletions(-)
 create mode 100644 tests/bugs/shard/issue-1243.t

diff --git a/tests/bugs/shard/issue-1243.t b/tests/bugs/shard/issue-1243.t
new file mode 100644
index 0000000..b0c092c
--- /dev/null
+++ b/tests/bugs/shard/issue-1243.t
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+. $(dirname $0)/../../include.rc
+
+cleanup;
+
+TEST glusterd
+TEST pidof glusterd
+TEST $CLI volume create $V0 $H0:$B0/${V0}{0,1}
+TEST $CLI volume set $V0 features.shard on
+TEST $CLI volume set $V0 features.shard-block-size 4MB
+TEST $CLI volume set $V0 performance.quick-read off
+TEST $CLI volume set $V0 performance.io-cache off
+TEST $CLI volume set $V0 performance.read-ahead off
+TEST $CLI volume set $V0 performance.strict-o-direct on
+TEST $CLI volume start $V0
+
+TEST $GFS --volfile-id=$V0 --volfile-server=$H0 $M0
+
+TEST $CLI volume set $V0 md-cache-timeout 10
+
+# Write data into a file such that its size crosses shard-block-size
+TEST dd if=/dev/zero of=$M0/foo bs=1048576 count=8 oflag=direct
+
+# Execute a setxattr on the file.
+TEST setfattr -n trusted.libvirt -v some-value $M0/foo
+
+# Size of the file should be the aggregated size, not the shard-block-size
+EXPECT '8388608' stat -c %s $M0/foo
+
+cleanup
diff --git a/xlators/features/shard/src/shard.c b/xlators/features/shard/src/shard.c
index ee38ed2..6ae4c41 100644
--- a/xlators/features/shard/src/shard.c
+++ b/xlators/features/shard/src/shard.c
@@ -5929,36 +5929,206 @@ out:
   return 0;
 }
 
-int32_t shard_fsetxattr(call_frame_t *frame, xlator_t *this, fd_t *fd,
-                        dict_t *dict, int32_t flags, dict_t *xdata) {
-  int op_errno = EINVAL;
+int32_t shard_common_set_xattr_cbk(call_frame_t *frame, void *cookie,
+                                   xlator_t *this, int32_t op_ret,
+                                   int32_t op_errno, dict_t *xdata) {
+    int ret = -1;
+    struct iatt *prebuf = NULL;
+    struct iatt *postbuf = NULL;
+    struct iatt *stbuf = NULL;
+    data_t *data = NULL;
+    shard_local_t *local = NULL;
 
-  if (frame->root->pid != GF_CLIENT_PID_GSYNCD) {
-    GF_IF_INTERNAL_XATTR_GOTO(SHARD_XATTR_PREFIX "*", dict, op_errno, out);
-  }
+    local = frame->local;
 
-  STACK_WIND_TAIL(frame, FIRST_CHILD(this), FIRST_CHILD(this)->fops->fsetxattr,
-                  fd, dict, flags, xdata);
-  return 0;
-out:
-  shard_common_failure_unwind(GF_FOP_FSETXATTR, frame, -1, op_errno);
-  return 0;
+    if (op_ret < 0) {
+        local->op_ret = op_ret;
+        local->op_errno = op_errno;
+        goto err;
+    }
+
+    if (!xdata)
+        goto unwind;
+
+    data = dict_get(xdata, GF_PRESTAT);
+    if (data) {
+        stbuf = data_to_iatt(data, GF_PRESTAT);
+        prebuf = GF_MALLOC(sizeof(struct iatt), gf_common_mt_char);
+        if (prebuf == NULL) {
+            local->op_ret = -1;
+            local->op_errno = ENOMEM;
+            goto err;
+        }
+        *prebuf = *stbuf;
+        prebuf->ia_size = local->prebuf.ia_size;
+        prebuf->ia_blocks = local->prebuf.ia_blocks;
+        ret = dict_set_iatt(xdata, GF_PRESTAT, prebuf, false);
+        if (ret < 0) {
+            local->op_ret = -1;
+            local->op_errno = ENOMEM;
+            goto err;
+        }
+        prebuf = NULL;
+    }
+
+    data = dict_get(xdata, GF_POSTSTAT);
+    if (data) {
+        stbuf = data_to_iatt(data, GF_POSTSTAT);
+        postbuf = GF_MALLOC(sizeof(struct iatt), gf_common_mt_char);
+        if (postbuf == NULL) {
+            local->op_ret = -1;
+            local->op_errno = ENOMEM;
+            goto err;
+        }
+        *postbuf = *stbuf;
+        postbuf->ia_size = local->prebuf.ia_size;
+        postbuf->ia_blocks = local->prebuf.ia_blocks;
+        ret = dict_set_iatt(xdata, GF_POSTSTAT, postbuf, false);
+        if (ret < 0) {
+            local->op_ret = -1;
+            local->op_errno = ENOMEM;
+            goto err;
+        }
+        postbuf = NULL;
+    }
+
+unwind:
+    if (local->fd)
+        SHARD_STACK_UNWIND(fsetxattr, frame, local->op_ret, local->op_errno,
+                           xdata);
+    else
+        SHARD_STACK_UNWIND(setxattr, frame, local->op_ret, local->op_errno,
+                           xdata);
+    return 0;
+
+err:
+    GF_FREE(prebuf);
+    GF_FREE(postbuf);
+    shard_common_failure_unwind(local->fop, frame, local->op_ret,
+                                local->op_errno);
+    return 0;
 }
 
-int32_t shard_setxattr(call_frame_t *frame, xlator_t *this, loc_t *loc,
-                       dict_t *dict, int32_t flags, dict_t *xdata) {
-  int op_errno = EINVAL;
+int32_t shard_post_lookup_set_xattr_handler(call_frame_t *frame,
+                                            xlator_t *this) {
+    shard_local_t *local = NULL;
 
-  if (frame->root->pid != GF_CLIENT_PID_GSYNCD) {
-    GF_IF_INTERNAL_XATTR_GOTO(SHARD_XATTR_PREFIX "*", dict, op_errno, out);
-  }
+    local = frame->local;
 
-  STACK_WIND_TAIL(frame, FIRST_CHILD(this), FIRST_CHILD(this)->fops->setxattr,
-                  loc, dict, flags, xdata);
-  return 0;
-out:
-  shard_common_failure_unwind(GF_FOP_SETXATTR, frame, -1, op_errno);
-  return 0;
+    if (local->op_ret < 0) {
+        shard_common_failure_unwind(local->fop, frame, local->op_ret,
+                                    local->op_errno);
+        return 0;
+    }
+
+    if (local->fd)
+        STACK_WIND(frame, shard_common_set_xattr_cbk, FIRST_CHILD(this),
+                   FIRST_CHILD(this)->fops->fsetxattr, local->fd,
+                   local->xattr_req, local->flags, local->xattr_rsp);
+    else
+        STACK_WIND(frame, shard_common_set_xattr_cbk, FIRST_CHILD(this),
+                   FIRST_CHILD(this)->fops->setxattr, &local->loc,
+                   local->xattr_req, local->flags, local->xattr_rsp);
+    return 0;
+}
+
+int32_t shard_common_set_xattr(call_frame_t *frame, xlator_t *this,
+                               glusterfs_fop_t fop, loc_t *loc, fd_t *fd,
+                               dict_t *dict, int32_t flags, dict_t *xdata) {
+    int ret = -1;
+    int op_errno = ENOMEM;
+    uint64_t block_size = 0;
+    shard_local_t *local = NULL;
+    inode_t *inode = loc ? loc->inode : fd->inode;
+
+    if ((IA_ISDIR(inode->ia_type)) || (IA_ISLNK(inode->ia_type))) {
+        if (loc)
+            STACK_WIND_TAIL(frame, FIRST_CHILD(this),
+                            FIRST_CHILD(this)->fops->setxattr, loc, dict, flags,
+                            xdata);
+        else
+            STACK_WIND_TAIL(frame, FIRST_CHILD(this),
+                            FIRST_CHILD(this)->fops->fsetxattr, fd, dict, flags,
+                            xdata);
+        return 0;
+    }
+
+    /* Sharded or not, if shard's special xattrs are attempted to be set,
+     * fail the fop with EPERM (except if the client is gsyncd.
+     */
+    if (frame->root->pid != GF_CLIENT_PID_GSYNCD) {
+        GF_IF_INTERNAL_XATTR_GOTO(SHARD_XATTR_PREFIX "*", dict, op_errno, err);
+    }
+
+    ret = shard_inode_ctx_get_block_size(inode, this, &block_size);
+    if (ret) {
+        gf_msg(this->name, GF_LOG_ERROR, 0, SHARD_MSG_INODE_CTX_GET_FAILED,
+               "Failed to get block size from inode ctx of %s",
+               uuid_utoa(inode->gfid));
+        goto err;
+    }
+
+    if (!block_size || frame->root->pid == GF_CLIENT_PID_GSYNCD) {
+        if (loc)
+            STACK_WIND_TAIL(frame, FIRST_CHILD(this),
+                            FIRST_CHILD(this)->fops->setxattr, loc, dict, flags,
+                            xdata);
+        else
+            STACK_WIND_TAIL(frame, FIRST_CHILD(this),
+                            FIRST_CHILD(this)->fops->fsetxattr, fd, dict, flags,
+                            xdata);
+        return 0;
+    }
+
+    local = mem_get0(this->local_pool);
+    if (!local)
+        goto err;
+
+    frame->local = local;
+    local->fop = fop;
+    if (loc) {
+        if (loc_copy(&local->loc, loc) != 0)
+            goto err;
+    }
+
+    if (fd) {
+        local->fd = fd_ref(fd);
+        local->loc.inode = inode_ref(fd->inode);
+        gf_uuid_copy(local->loc.gfid, fd->inode->gfid);
+    }
+    local->flags = flags;
+    /* Reusing local->xattr_req and local->xattr_rsp to store the setxattr dict
+     * and the xdata dict
+     */
+    if (dict)
+        local->xattr_req = dict_ref(dict);
+    if (xdata)
+        local->xattr_rsp = dict_ref(xdata);
+
+    /* To-Do: Switch from LOOKUP which is path-based, to FSTAT if the fop is
+     * on an fd. This comes under a generic class of bugs in shard tracked by
+     * bz #1782428.
+     */
+    shard_lookup_base_file(frame, this, &local->loc,
+                           shard_post_lookup_set_xattr_handler);
+    return 0;
+err:
+    shard_common_failure_unwind(fop, frame, -1, op_errno);
+    return 0;
+}
+
+int32_t shard_fsetxattr(call_frame_t *frame, xlator_t *this, fd_t *fd,
+                        dict_t *dict, int32_t flags, dict_t *xdata) {
+    shard_common_set_xattr(frame, this, GF_FOP_FSETXATTR, NULL, fd, dict, flags,
+                           xdata);
+    return 0;
+}
+
+int32_t shard_setxattr(call_frame_t *frame, xlator_t *this, loc_t *loc,
+                       dict_t *dict, int32_t flags, dict_t *xdata) {
+    shard_common_set_xattr(frame, this, GF_FOP_SETXATTR, loc, NULL, dict, flags,
+                           xdata);
+    return 0;
 }
 
 int shard_post_setattr_handler(call_frame_t *frame, xlator_t *this) {
-- 
1.8.3.1