Skip to content

Commit

Permalink
DAOS-14547: Source pool/cont only needs read permission
Browse files Browse the repository at this point in the history
Open the source pool and container with RO, and the destination with RW.

Signed-off-by: Dalton Bohning <dalton.bohning@intel.com>
  • Loading branch information
daltonbohning committed Feb 22, 2024
1 parent 9acb07a commit 0353932
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
50 changes: 31 additions & 19 deletions src/common/mfu_daos.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ int daos_parse_path(
} else {
strncpy(path, dattr.da_rel_path, path_len);
}
} else if (strncmp(path, "daos:", 5) == 0) {
/* Actual error, since we expect a daos path */
rc = -1;
} else {
/* If basename does not exist yet then duns_resolve_path will fail even
* if dirname is a UNS path */
Expand Down Expand Up @@ -354,9 +357,6 @@ int daos_parse_path(
snprintf(*pool_str, DAOS_PROP_LABEL_MAX_LEN + 1, "%s", dattr.da_pool);
snprintf(*cont_str, DAOS_PROP_LABEL_MAX_LEN + 1, "%s", dattr.da_cont);
strncpy(path, dattr.da_rel_path, path_len);
} else if (strncmp(path, "daos:", 5) == 0) {
/* Actual error, since we expect a daos path */
rc = -1;
} else {
/* We didn't parse a daos path,
* but we weren't necessarily looking for one */
Expand Down Expand Up @@ -1022,7 +1022,9 @@ int daos_connect(
daos_handle_t* coh,
bool force_serialize,
bool connect_pool,
unsigned int pool_connect_flags,
bool create_cont,
unsigned int cont_open_flags,
bool require_new_cont,
bool preserve,
mfu_file_t* mfu_src_file,
Expand Down Expand Up @@ -1062,9 +1064,9 @@ int daos_connect(
if (connect_pool) {
daos_pool_info_t pool_info = {0};
#if DAOS_API_VERSION_MAJOR < 1
rc = daos_pool_connect(*pool, NULL, NULL, DAOS_PC_RW, poh, &pool_info, NULL);
rc = daos_pool_connect(*pool, NULL, NULL, pool_connect_flags, poh, &pool_info, NULL);
#else
rc = daos_pool_connect(*pool, NULL, DAOS_PC_RW, poh, &pool_info, NULL);
rc = daos_pool_connect(*pool, NULL, pool_connect_flags, poh, &pool_info, NULL);
#endif
if (rc != 0) {
MFU_LOG(MFU_LOG_ERR, "Failed to connect to pool: "DF_RC, DP_RC(rc));
Expand All @@ -1082,9 +1084,9 @@ int daos_connect(
* not generated */
char cont_str[130];
uuid_unparse(da->dst_cont_uuid, cont_str);
rc = daos_cont_open(*poh, cont_str, DAOS_COO_RW, coh, &co_info, NULL);
rc = daos_cont_open(*poh, cont_str, cont_open_flags, coh, &co_info, NULL);
} else {
rc = daos_cont_open(*poh, *cont, DAOS_COO_RW, coh, &co_info, NULL);
rc = daos_cont_open(*poh, *cont, cont_open_flags, coh, &co_info, NULL);
}
if (rc != 0) {
if (rc != -DER_NONEXIST || !create_cont) {
Expand Down Expand Up @@ -1146,7 +1148,7 @@ int daos_connect(
/* if nothing is passed in for destination a uuid is always
* generated unless user passed one in, destination container
* labels are not generated */
rc = dfs_cont_create(*poh, da->dst_cont_uuid, &attr, NULL, NULL);
rc = dfs_cont_create(*poh, &da->dst_cont_uuid, &attr, NULL, NULL);
}
if (rc != 0) {
MFU_LOG(MFU_LOG_ERR, "Failed to create container: (%d %s)", rc, strerror(rc));
Expand All @@ -1156,7 +1158,7 @@ int daos_connect(
if (dst_cont_passed && !is_uuid) {
rc = daos_cont_create_with_label(*poh, *cont, props, &da->dst_cont_uuid, NULL);
} else {
rc = daos_cont_create(*poh, da->dst_cont_uuid, props, NULL);
rc = daos_cont_create(*poh, &da->dst_cont_uuid, props, NULL);
}
if (rc != 0) {
MFU_LOG(MFU_LOG_ERR, "Failed to create container: "DF_RC, DP_RC(rc));
Expand All @@ -1174,11 +1176,11 @@ int daos_connect(

/* try to open it again */
if (dst_cont_passed && !is_uuid) {
rc = daos_cont_open(*poh, *cont, DAOS_COO_RW, coh, &co_info, NULL);
rc = daos_cont_open(*poh, *cont, cont_open_flags, coh, &co_info, NULL);
} else {
char cont_str[130];
uuid_unparse(da->dst_cont_uuid, cont_str);
rc = daos_cont_open(*poh, cont_str, DAOS_COO_RW, coh, &co_info, NULL);
rc = daos_cont_open(*poh, cont_str, cont_open_flags, coh, &co_info, NULL);
}
if (rc != 0) {
MFU_LOG(MFU_LOG_ERR, "Failed to open container: "DF_RC, DP_RC(rc));
Expand Down Expand Up @@ -1572,7 +1574,17 @@ int daos_setup(
/* Check if containers are in the same pool */
bool same_pool = (strcmp(da->src_pool, da->dst_pool) == 0);

bool connect_pool = true;
/* For POSIX, the source only needs read, but the destination needs read and write.
* For DAOS (object-level), both need read and write. */
unsigned int src_pool_connect_flags = DAOS_PC_RW;
unsigned int dst_pool_connect_flags = DAOS_PC_RW;
unsigned int src_cont_open_flags = DAOS_COO_RW;
unsigned int dst_cont_open_flags = DAOS_COO_RW;
if (!same_pool && mfu_src_file->type == POSIX) {
src_pool_connect_flags = DAOS_PC_RO;
src_cont_open_flags = DAOS_COO_RO;
}

bool create_cont = false;
bool require_new_cont = false;
bool preserve = false;
Expand All @@ -1589,7 +1601,7 @@ int daos_setup(
}
tmp_rc = daos_connect(rank, da, &da->src_pool, &da->src_cont,
&da->src_poh, &da->src_coh, false,
connect_pool, create_cont, require_new_cont,
true, src_pool_connect_flags, create_cont, src_cont_open_flags, require_new_cont,
preserve, mfu_src_file, dst_cont_passed);
if (tmp_rc != 0) {
/* tmp_rc from daos_connect is collective */
Expand Down Expand Up @@ -1663,17 +1675,17 @@ int daos_setup(
}
}
if (same_pool) {
connect_pool = false;
/* Use the same handle as the source */
tmp_rc = daos_connect(rank, da, &da->dst_pool, &da->dst_cont,
&da->src_poh, &da->dst_coh, false,
connect_pool, create_cont, require_new_cont,
preserve, mfu_src_file, dst_cont_passed);
false, src_pool_connect_flags, create_cont, src_cont_open_flags,
require_new_cont, preserve, mfu_src_file, dst_cont_passed);
} else {
connect_pool = true;
/* Connect to a different handle */
tmp_rc = daos_connect(rank, da, &da->dst_pool, &da->dst_cont,
&da->dst_poh, &da->dst_coh, false,
connect_pool, create_cont, require_new_cont,
preserve, mfu_src_file, dst_cont_passed);
true, dst_pool_connect_flags, create_cont, dst_cont_open_flags,
require_new_cont, preserve, mfu_src_file, dst_cont_passed);
}
if (tmp_rc != 0) {
/* tmp_rc from daos_connect is collective */
Expand Down
2 changes: 2 additions & 0 deletions src/common/mfu_daos.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,9 @@ int daos_connect(
daos_handle_t* coh,
bool force_serialize,
bool connect_pool,
unsigned int pool_connect_flags,
bool create_cont,
unsigned int cont_open_flags,
bool require_new_cont,
bool preserve,
mfu_file_t* mfu_src_file,
Expand Down

0 comments on commit 0353932

Please sign in to comment.