Skip to content

Commit a88fdd3

Browse files
chenjinhaochen1195585098
authored andcommitted
linkfile: use fops->create in dht_linkfile_create
A newly created linkfile will be deleted for the race, after this, the gfid between linkfile and datafile may get mismatched. And shards deletion process is also affected by such a mismatch, most shards in BRICK_PATH/.shard cannot be removed correctly and space cannot be released. To fix this race, replace mknod with create during linkfile creation, in this case, we can keep this linkfile opening during the whole linkfile and datafile creations. A linkfile will not be regarded as stale and deleted then, because its fd is opened and posix_unlink can handle it properly. In this patch, the linkfile and datafile creation process is as below: dht hashed_subvol cached_subvol --> | | | | | | | a.create tmp fd as local->fd | | | b.send fops->create | | |---- dht_linkfile_create ---->| | | | | | c.succeed to create linkfile,| | |<-- dht_linkfile_create_cbk --| | | | |--- corresponding fop for datafile, mknod, create, etc. --->| | | |<---------- datafile fop cbk ----------| | | | | | | d.stack unwind/destroy | | | e.clear dht_local_t in | | <-- | dht_local_wipe | | | | | A tmp local->fd will be created for non-fd-based fops to ensure safe access to fd or its member in subsequent procedures. Once this linkfile was successfully created, its fd_count will be increased in server cbk and passed to client if necessary. Then, between phase c and phase e, linkfile will not be deleted by mistake since later processes will know this linkfile is being used, instead of stale. After phase e, this linkfile links to a datafile, so it is valid. This change should also be applied during dht_lookup_everywhere_cbk. Fixes: #4548 Signed-off-by: chenjinhao <[email protected]>
1 parent 9e95395 commit a88fdd3

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

xlators/cluster/dht/src/dht-common.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2426,12 +2426,20 @@ dht_lookup_everywhere_done(call_frame_t *frame, xlator_t *this)
24262426
gf_msg_debug(this->name, 0,
24272427
"No Cached was found and "
24282428
"unlink on hashed was skipped"
2429-
" so performing now: %s",
2430-
local->loc.path);
2431-
FRAME_SU_DO(frame, dht_local_t);
2432-
STACK_WIND(frame, dht_lookup_unlink_stale_linkto_cbk,
2433-
hashed_subvol, hashed_subvol->fops->unlink,
2434-
&local->loc, 0, local->xattr_req);
2429+
" so performing now: %s. fd_count = %d",
2430+
local->loc.path,
2431+
local->skip_unlink.opend_fd_count);
2432+
if (local->skip_unlink.opend_fd_count == 0) {
2433+
FRAME_SU_DO(frame, dht_local_t);
2434+
STACK_WIND(frame, dht_lookup_unlink_stale_linkto_cbk,
2435+
hashed_subvol, hashed_subvol->fops->unlink,
2436+
&local->loc, 0, local->xattr_req);
2437+
} else {
2438+
/* Skip linkfile deletion, this linkfile may be in used
2439+
* because its fd_count > 0 */
2440+
DHT_STACK_UNWIND(lookup, frame, -1, ENOENT, NULL, NULL, NULL,
2441+
NULL);
2442+
}
24352443
}
24362444

24372445
} else {

xlators/cluster/dht/src/dht-linkfile.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
cases as published by the Free Software Foundation.
99
*/
1010

11+
#include <fcntl.h>
1112
#include <glusterfs/compat.h>
1213
#include "dht-common.h"
1314

@@ -45,7 +46,7 @@ dht_linkfile_lookup_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
4546

4647
static int
4748
dht_linkfile_create_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
48-
int op_ret, int op_errno, inode_t *inode,
49+
int op_ret, int op_errno, fd_t *fd, inode_t *inode,
4950
struct iatt *stbuf, struct iatt *preparent,
5051
struct iatt *postparent, dict_t *xdata)
5152
{
@@ -147,9 +148,15 @@ dht_linkfile_create(call_frame_t *frame, fop_mknod_cbk_t linkfile_cbk,
147148
/* Always create as root:root. dht_linkfile_attr_heal fixes the
148149
* ownsership */
149150
FRAME_SU_DO(frame, dht_local_t);
151+
152+
if (!local->fd) {
153+
local->fd = fd_create(loc->inode, frame->root->pid);
154+
local->flags |= (O_CREAT | O_EXCL);
155+
}
156+
150157
STACK_WIND_COOKIE(frame, dht_linkfile_create_cbk, fromvol, fromvol,
151-
fromvol->fops->mknod, loc, S_IFREG | DHT_LINKFILE_MODE, 0,
152-
0, dict);
158+
fromvol->fops->create, loc, local->flags,
159+
S_IFREG | DHT_LINKFILE_MODE, 0, local->fd, dict);
153160

154161
if (need_unref && dict)
155162
dict_unref(dict);

0 commit comments

Comments
 (0)