Skip to content

Commit d93646b

Browse files
author
Sergey Fukanchik
committed
[PBCKP-314] rewrite fio_mkdir to use pio
1 parent 2f2d879 commit d93646b

File tree

2 files changed

+37
-27
lines changed

2 files changed

+37
-27
lines changed

src/utils/file.c

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,32 +1505,8 @@ dir_create_dir(const char *dir, mode_t mode, bool strict)
15051505
int
15061506
fio_mkdir(fio_location location, const char* path, int mode, bool strict)
15071507
{
1508-
if (fio_is_remote(location))
1509-
{
1510-
fio_header hdr = {
1511-
.cop = FIO_MKDIR,
1512-
.handle = strict ? 1 : 0, /* ugly "hack" to pass more params*/
1513-
.size = strlen(path) + 1,
1514-
.arg = mode,
1515-
};
1516-
1517-
IO_CHECK(fio_write_all(fio_stdout, &hdr, sizeof(hdr)), sizeof(hdr));
1518-
IO_CHECK(fio_write_all(fio_stdout, path, hdr.size), hdr.size);
1519-
1520-
IO_CHECK(fio_read_all(fio_stdin, &hdr, sizeof(hdr)), sizeof(hdr));
1521-
Assert(hdr.cop == FIO_MKDIR);
1522-
1523-
if (hdr.arg != 0)
1524-
{
1525-
errno = hdr.arg;
1526-
return -1;
1527-
}
1528-
return 0;
1529-
}
1530-
else
1531-
{
1532-
return dir_create_dir(path, mode, strict);
1533-
}
1508+
pioDrive_i drive = pioDriveForLocation(location);
1509+
return $i(pioMakeDir, drive, .path = path, .mode = mode, .strict = strict);
15341510
}
15351511

15361512
static void
@@ -3537,6 +3513,13 @@ pioLocalDrive_pioIsRemote(VSelf)
35373513
return false;
35383514
}
35393515

3516+
static int
3517+
pioLocalDrive_pioMakeDir(VSelf, const char *path, mode_t mode, bool strict)
3518+
{
3519+
FOBJ_FUNC_ARP();
3520+
return dir_create_dir(path, mode, strict);
3521+
}
3522+
35403523
static void
35413524
pioLocalDrive_pioListDir(VSelf, parray *files, const char *root, bool handle_tablespaces,
35423525
bool follow_symlink, bool backup_logs, bool skip_hidden,
@@ -3853,6 +3836,31 @@ pioRemoteDrive_pioIsRemote(VSelf)
38533836
return true;
38543837
}
38553838

3839+
static int
3840+
pioRemoteDrive_pioMakeDir(VSelf, const char *path, mode_t mode, bool strict)
3841+
{
3842+
FOBJ_FUNC_ARP();
3843+
fio_header hdr = {
3844+
.cop = FIO_MKDIR,
3845+
.handle = strict ? 1 : 0, /* ugly "hack" to pass more params*/
3846+
.size = strlen(path) + 1,
3847+
.arg = mode,
3848+
};
3849+
3850+
IO_CHECK(fio_write_all(fio_stdout, &hdr, sizeof(hdr)), sizeof(hdr));
3851+
IO_CHECK(fio_write_all(fio_stdout, path, hdr.size), hdr.size);
3852+
3853+
IO_CHECK(fio_read_all(fio_stdin, &hdr, sizeof(hdr)), sizeof(hdr));
3854+
Assert(hdr.cop == FIO_MKDIR);
3855+
3856+
if (hdr.arg != 0)
3857+
{
3858+
errno = hdr.arg;
3859+
return -1;
3860+
}
3861+
return 0;
3862+
}
3863+
38563864
static void
38573865
pioRemoteDrive_pioListDir(VSelf, parray *files, const char *root, bool handle_tablespaces,
38583866
bool follow_symlink, bool backup_logs, bool skip_hidden,

src/utils/file.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ typedef struct stat stat_t;
243243
#define mth__pioGetCRC32 pg_crc32, (path_t, path), (bool, compressed), \
244244
(err_i *, err)
245245
#define mth__pioIsRemote bool
246+
#define mth__pioMakeDir int, (const char *, path), (mode_t, mode), (bool, strict)
246247
#define mth__pioListDir void, (parray *, files), (const char *, root), \
247248
(bool, handle_tablespaces), (bool, symlink_and_hidden), \
248249
(bool, backup_logs), (bool, skip_hidden), (int, external_dir_num)
@@ -255,11 +256,12 @@ fobj_method(pioRename);
255256
fobj_method(pioExists);
256257
fobj_method(pioIsRemote);
257258
fobj_method(pioGetCRC32);
259+
fobj_method(pioMakeDir);
258260
fobj_method(pioListDir);
259261
fobj_method(pioRemoveDir);
260262

261263
#define iface__pioDrive mth(pioOpen, pioStat, pioRemove, pioRename), \
262-
mth(pioExists, pioGetCRC32, pioIsRemote, pioListDir, pioRemoveDir)
264+
mth(pioExists, pioGetCRC32, pioIsRemote, pioMakeDir, pioListDir, pioRemoveDir)
263265
fobj_iface(pioDrive);
264266

265267
#define kls__pioLocalDrive iface__pioDrive, iface(pioDrive)

0 commit comments

Comments
 (0)