Skip to content

Commit 0d3506d

Browse files
author
Sergey Fukanchik
committed
[PBCKP-314] rewrite fio_mkdir to use pio
1 parent 5f419c3 commit 0d3506d

File tree

2 files changed

+37
-28
lines changed

2 files changed

+37
-28
lines changed

src/utils/file.c

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,32 +1536,8 @@ dir_create_dir(const char *dir, mode_t mode, bool strict)
15361536
int
15371537
fio_mkdir(fio_location location, const char* path, int mode, bool strict)
15381538
{
1539-
if (fio_is_remote(location))
1540-
{
1541-
fio_header hdr = {
1542-
.cop = FIO_MKDIR,
1543-
.handle = strict ? 1 : 0, /* ugly "hack" to pass more params*/
1544-
.size = strlen(path) + 1,
1545-
.arg = mode,
1546-
};
1547-
1548-
IO_CHECK(fio_write_all(fio_stdout, &hdr, sizeof(hdr)), sizeof(hdr));
1549-
IO_CHECK(fio_write_all(fio_stdout, path, hdr.size), hdr.size);
1550-
1551-
IO_CHECK(fio_read_all(fio_stdin, &hdr, sizeof(hdr)), sizeof(hdr));
1552-
Assert(hdr.cop == FIO_MKDIR);
1553-
1554-
if (hdr.arg != 0)
1555-
{
1556-
errno = hdr.arg;
1557-
return -1;
1558-
}
1559-
return 0;
1560-
}
1561-
else
1562-
{
1563-
return dir_create_dir(path, mode, strict);
1564-
}
1539+
pioDrive_i drive = pioDriveForLocation(location);
1540+
return $i(pioMakeDir, drive, .path = path, .mode = mode, .strict = strict);
15651541
}
15661542

15671543
static void
@@ -4136,6 +4112,13 @@ pioLocalDrive_pioIsRemote(VSelf)
41364112
return false;
41374113
}
41384114

4115+
static int
4116+
pioLocalDrive_pioMakeDir(VSelf, const char *path, mode_t mode, bool strict)
4117+
{
4118+
FOBJ_FUNC_ARP();
4119+
return dir_create_dir(path, mode, strict);
4120+
}
4121+
41394122
static void
41404123
pioLocalDrive_pioListDir(VSelf, parray *files, const char *root, bool handle_tablespaces,
41414124
bool follow_symlink, bool backup_logs, bool skip_hidden,
@@ -4452,6 +4435,31 @@ pioRemoteDrive_pioIsRemote(VSelf)
44524435
return true;
44534436
}
44544437

4438+
static int
4439+
pioRemoteDrive_pioMakeDir(VSelf, const char *path, mode_t mode, bool strict)
4440+
{
4441+
FOBJ_FUNC_ARP();
4442+
fio_header hdr = {
4443+
.cop = FIO_MKDIR,
4444+
.handle = strict ? 1 : 0, /* ugly "hack" to pass more params*/
4445+
.size = strlen(path) + 1,
4446+
.arg = mode,
4447+
};
4448+
4449+
IO_CHECK(fio_write_all(fio_stdout, &hdr, sizeof(hdr)), sizeof(hdr));
4450+
IO_CHECK(fio_write_all(fio_stdout, path, hdr.size), hdr.size);
4451+
4452+
IO_CHECK(fio_read_all(fio_stdin, &hdr, sizeof(hdr)), sizeof(hdr));
4453+
Assert(hdr.cop == FIO_MKDIR);
4454+
4455+
if (hdr.arg != 0)
4456+
{
4457+
errno = hdr.arg;
4458+
return -1;
4459+
}
4460+
return 0;
4461+
}
4462+
44554463
static void
44564464
pioRemoteDrive_pioListDir(VSelf, parray *files, const char *root, bool handle_tablespaces,
44574465
bool follow_symlink, bool backup_logs, bool skip_hidden,

src/utils/file.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ typedef struct stat stat_t;
254254
#define mth__pioGetCRC32 pg_crc32, (path_t, path), (bool, compressed), \
255255
(err_i *, err)
256256
#define mth__pioIsRemote bool
257+
#define mth__pioMakeDir int, (const char *, path), (mode_t, mode), (bool, strict)
257258
#define mth__pioListDir void, (parray *, files), (const char *, root), \
258259
(bool, handle_tablespaces), (bool, symlink_and_hidden), \
259260
(bool, backup_logs), (bool, skip_hidden), (int, external_dir_num)
@@ -266,12 +267,12 @@ fobj_method(pioRename);
266267
fobj_method(pioExists);
267268
fobj_method(pioIsRemote);
268269
fobj_method(pioGetCRC32);
270+
fobj_method(pioMakeDir);
269271
fobj_method(pioListDir);
270272
fobj_method(pioRemoveDir);
271273

272274
#define iface__pioDrive mth(pioOpen, pioStat, pioRemove, pioRename), \
273-
mth(pioExists, pioGetCRC32, pioIsRemote), \
274-
mth(pioListDir, pioRemoveDir)
275+
mth(pioExists, pioGetCRC32, pioIsRemote, pioMakeDir, pioListDir, pioRemoveDir)
275276
fobj_iface(pioDrive);
276277

277278
extern pioDrive_i pioDriveForLocation(fio_location location);

0 commit comments

Comments
 (0)