int cfs_mkdir_safe(struct ceph_mount_info* _fs, const char* _path, mode_t _mode) { int ret = 0; int ceph_opendir_res = -1; struct ceph_dir_result* cfs_dir = NULL; if (unlikely(pthread_mutex_lock(&cfs_mkdir_safe_lock))) panic("pthread_mutex_lock"); ceph_opendir_res = ceph_opendir(_fs, _path, &cfs_dir); if (unlikely(ceph_opendir_res != 0)) ret = ceph_mkdir(_fs, _path, _mode); else ceph_closedir(_fs, cfs_dir); if (unlikely(pthread_mutex_unlock(&cfs_mkdir_safe_lock))) panic("pthread_mutex_unlock"); return ret; }
static int cephwrap_mkdir(struct vfs_handle_struct *handle, const struct smb_filename *smb_fname, mode_t mode) { int result; char *parent = NULL; const char *path = smb_fname->base_name; DBG_DEBUG("[CEPH] mkdir(%p, %s)\n", handle, path); if (lp_inherit_acls(SNUM(handle->conn)) && parent_dirname(talloc_tos(), path, &parent, NULL) && directory_has_default_acl(handle->conn, parent)) { mode = 0777; } TALLOC_FREE(parent); result = ceph_mkdir(handle->data, path, mode); return WRAP_RETURN(result); }
/* * Create a parent directory using the cephfs API. * * We don't use cephfs_mkdirs as we want to keep track which * directories got created by us. */ static inline bool cephfs_makedirs(plugin_ctx *p_ctx, const char *directory) { char *bp; struct stat st; bool retval = false; POOL_MEM new_directory(PM_FNAME); pm_strcpy(new_directory, directory); /* * See if the parent exists. */ bp = strrchr(new_directory.c_str(), '/'); if (bp) { /* * See if we reached the root. */ if (bp == new_directory.c_str()) { /* * Create the directory. */ if (ceph_mkdir(p_ctx->cmount, directory, 0750) == 0) { if (!p_ctx->path_list) { p_ctx->path_list = path_list_init(); } path_list_add(p_ctx->path_list, strlen(directory), directory); retval = true; } } else { *bp = '\0'; if (ceph_lstat(p_ctx->cmount, new_directory.c_str(), &st) != 0) { switch (errno) { case ENOENT: /* * Make sure our parent exists. */ retval = cephfs_makedirs(p_ctx, new_directory.c_str()); if (!retval) { return false; } /* * Create the directory. */ if (ceph_mkdir(p_ctx->cmount, directory, 0750) == 0) { if (!p_ctx->path_list) { p_ctx->path_list = path_list_init(); } path_list_add(p_ctx->path_list, strlen(directory), directory); retval = true; } break; default: break; } } else { retval = true; } } } return retval; }