Skip to content

Commit

Permalink
daos: daos_mknod implementation
Browse files Browse the repository at this point in the history
daos_mknod is implemented in two steps:
1. dfs_open(..., O_CREATE,...)
2. dfs_release(...)

daos_mknod and daos_open will both default the
filetype in mode to be S_IFREG.
And if any other filetype is passed in, they
will return an error.

Signed-off-by: Dalton Bohning <daltonx.bohning@intel.com>
  • Loading branch information
Dalton Bohning authored and daltonbohning committed Sep 22, 2020
1 parent 49a332b commit 867cb5e
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 5 deletions.
70 changes: 66 additions & 4 deletions src/common/mfu_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,61 @@ int mfu_lstat64(const char* path, struct stat64* buf)
return rc;
}

/* use a noop, daos does not have a mknod function */
/* emulates mknod with dfs_open, dfs_release */
int daos_mknod(const char* path, mode_t mode, dev_t dev, mfu_file_t* mfu_file)
{
return 0;
#ifdef DAOS_SUPPORT
/* Only regular files are supported at this time */
mode_t dfs_mode = mode | S_IFREG;
mode_t filetype = dfs_mode & S_IFMT;
if (filetype != S_IFREG) {
MFU_LOG(MFU_LOG_ERR, "Invalid entry type (not a file)");
errno = EINVAL;
return -1;
}

char* name = NULL;
char* dir_name = NULL;
parse_filename(path, &name, &dir_name);
assert(dir_name);

dfs_obj_t* parent = NULL;
int rc = dfs_lookup(mfu_file->dfs, dir_name, O_RDWR, &parent, NULL, NULL);
if (parent == NULL) {
MFU_LOG(MFU_LOG_ERR, "dfs_lookup %s failed", dir_name);
errno = ENOENT;
rc = -1;
}
else {
/* create regular file */
rc = dfs_open(mfu_file->dfs, parent, name,
dfs_mode, O_CREAT,
0, 0, NULL, &(mfu_file->obj));
if (rc) {
MFU_LOG(MFU_LOG_ERR, "dfs_open %s failed (%d %s)",
name, rc, strerror(rc));
errno = rc;
rc = -1;
}
else {
/* close the file */
rc = dfs_release(mfu_file->obj);
if (rc) {
MFU_LOG(MFU_LOG_ERR, "dfs_release %s failed (%d %s)",
path, rc, strerror(rc));
errno = rc;
rc = -1;
}
}
/* close the parent, ignoring errors since they have no direct impact */
dfs_release(parent);
}

mfu_free(&name);
mfu_free(&dir_name);

return rc;
#endif
}

int mfu_mknod(const char* path, mode_t mode, dev_t dev)
Expand Down Expand Up @@ -581,9 +632,18 @@ int mfu_hardlink(const char* oldpath, const char* newpath)
/*****************************
* Files
****************************/
void daos_open(const char* file, int flags, mode_t mode, mfu_file_t* mfu_file)
int daos_open(const char* file, int flags, mode_t mode, mfu_file_t* mfu_file)
{
#ifdef DAOS_SUPPORT
/* Only regular files are supported at this time */
mode_t dfs_mode = mode | S_IFREG;
mode_t filetype = dfs_mode & S_IFMT;
if (filetype != S_IFREG) {
MFU_LOG(MFU_LOG_ERR, "Invalid entry type (not a file)");
errno = EINVAL;
return -1;
}

char* name = NULL;
char* dir_name = NULL;
parse_filename(file, &name, &dir_name);
Expand All @@ -593,7 +653,7 @@ void daos_open(const char* file, int flags, mode_t mode, mfu_file_t* mfu_file)
int rc = dfs_lookup(mfu_file->dfs, dir_name, O_RDWR, &parent, NULL, NULL);
if (parent != NULL) {
rc = dfs_open(mfu_file->dfs, parent, name,
S_IFREG | mode, flags,
dfs_mode, flags,
0, 0, NULL, &(mfu_file->obj));
if (rc) {
MFU_LOG(MFU_LOG_ERR, "dfs_open %s failed (%d %s)",
Expand All @@ -609,6 +669,8 @@ void daos_open(const char* file, int flags, mode_t mode, mfu_file_t* mfu_file)

mfu_free(&name);
mfu_free(&dir_name);

return rc;
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion src/common/mfu_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ int mfu_symlink(const char* oldpath, const char* newpath);

/* open file with specified flags and mode, retry open a few times on failure */
void mfu_file_open(const char* file, int flags, mfu_file_t* mfu_file, ...);
void daos_open(const char* file, int flags, mode_t mode, mfu_file_t* mfu_file);
int daos_open(const char* file, int flags, mode_t mode, mfu_file_t* mfu_file);
int mfu_open(const char* file, int flags, ...);

/* close file */
Expand Down

0 comments on commit 867cb5e

Please sign in to comment.