Skip to content

Commit 9971668

Browse files
committed
DAOS-14547: Source pool/cont only needs read permission
Open the source pool and container with RO, and the destination with RW. Signed-off-by: Dalton Bohning <[email protected]>
1 parent 09e957d commit 9971668

File tree

3 files changed

+73
-29
lines changed

3 files changed

+73
-29
lines changed

src/common/mfu_daos.c

Lines changed: 69 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,9 @@ int daos_parse_path(
308308
} else {
309309
strncpy(path, dattr.da_rel_path, path_len);
310310
}
311+
} else if (strncmp(path, "daos:", 5) == 0) {
312+
/* Actual error, since we expect a daos path */
313+
rc = -1;
311314
} else {
312315
/* If basename does not exist yet then duns_resolve_path will fail even
313316
* if dirname is a UNS path */
@@ -354,9 +357,6 @@ int daos_parse_path(
354357
snprintf(*pool_str, DAOS_PROP_LABEL_MAX_LEN + 1, "%s", dattr.da_pool);
355358
snprintf(*cont_str, DAOS_PROP_LABEL_MAX_LEN + 1, "%s", dattr.da_cont);
356359
strncpy(path, dattr.da_rel_path, path_len);
357-
} else if (strncmp(path, "daos:", 5) == 0) {
358-
/* Actual error, since we expect a daos path */
359-
rc = -1;
360360
} else {
361361
/* We didn't parse a daos path,
362362
* but we weren't necessarily looking for one */
@@ -450,7 +450,7 @@ static int daos_set_paths(
450450
return rc;
451451
}
452452

453-
static int daos_get_cont_type(
453+
static int mfu_daos_get_cont_type(
454454
daos_handle_t coh,
455455
enum daos_cont_props* type)
456456
{
@@ -516,7 +516,7 @@ static int daos_check_cont_status(daos_handle_t coh, bool *status_healthy)
516516
* Try to set the file type based on the container type,
517517
* using api as a guide.
518518
*/
519-
static int daos_set_api_cont_type(
519+
static int mfu_daos_set_api_cont_type(
520520
mfu_file_t* mfu_file,
521521
enum daos_cont_props cont_type,
522522
daos_api_t api)
@@ -1022,7 +1022,9 @@ int daos_connect(
10221022
daos_handle_t* coh,
10231023
bool force_serialize,
10241024
bool connect_pool,
1025+
unsigned int pool_connect_flags,
10251026
bool create_cont,
1027+
unsigned int cont_open_flags,
10261028
bool require_new_cont,
10271029
bool preserve,
10281030
mfu_file_t* mfu_src_file,
@@ -1059,12 +1061,12 @@ int daos_connect(
10591061
}
10601062
#endif
10611063
/* Connect to DAOS pool */
1062-
if (connect_pool) {
1064+
if (connect_pool && !daos_handle_is_valid(*poh)) {
10631065
daos_pool_info_t pool_info = {0};
10641066
#if DAOS_API_VERSION_MAJOR < 1
1065-
rc = daos_pool_connect(*pool, NULL, NULL, DAOS_PC_RW, poh, &pool_info, NULL);
1067+
rc = daos_pool_connect(*pool, NULL, NULL, pool_connect_flags, poh, &pool_info, NULL);
10661068
#else
1067-
rc = daos_pool_connect(*pool, NULL, DAOS_PC_RW, poh, &pool_info, NULL);
1069+
rc = daos_pool_connect(*pool, NULL, pool_connect_flags, poh, &pool_info, NULL);
10681070
#endif
10691071
if (rc != 0) {
10701072
MFU_LOG(MFU_LOG_ERR, "Failed to connect to pool: "DF_RC, DP_RC(rc));
@@ -1082,9 +1084,9 @@ int daos_connect(
10821084
* not generated */
10831085
char cont_str[130];
10841086
uuid_unparse(da->dst_cont_uuid, cont_str);
1085-
rc = daos_cont_open(*poh, cont_str, DAOS_COO_RW, coh, &co_info, NULL);
1087+
rc = daos_cont_open(*poh, cont_str, cont_open_flags, coh, &co_info, NULL);
10861088
} else {
1087-
rc = daos_cont_open(*poh, *cont, DAOS_COO_RW, coh, &co_info, NULL);
1089+
rc = daos_cont_open(*poh, *cont, cont_open_flags, coh, &co_info, NULL);
10881090
}
10891091
if (rc != 0) {
10901092
if (rc != -DER_NONEXIST || !create_cont) {
@@ -1146,7 +1148,7 @@ int daos_connect(
11461148
/* if nothing is passed in for destination a uuid is always
11471149
* generated unless user passed one in, destination container
11481150
* labels are not generated */
1149-
rc = dfs_cont_create(*poh, da->dst_cont_uuid, &attr, NULL, NULL);
1151+
rc = dfs_cont_create(*poh, &da->dst_cont_uuid, &attr, NULL, NULL);
11501152
}
11511153
if (rc != 0) {
11521154
MFU_LOG(MFU_LOG_ERR, "Failed to create container: (%d %s)", rc, strerror(rc));
@@ -1156,7 +1158,7 @@ int daos_connect(
11561158
if (dst_cont_passed && !is_uuid) {
11571159
rc = daos_cont_create_with_label(*poh, *cont, props, &da->dst_cont_uuid, NULL);
11581160
} else {
1159-
rc = daos_cont_create(*poh, da->dst_cont_uuid, props, NULL);
1161+
rc = daos_cont_create(*poh, &da->dst_cont_uuid, props, NULL);
11601162
}
11611163
if (rc != 0) {
11621164
MFU_LOG(MFU_LOG_ERR, "Failed to create container: "DF_RC, DP_RC(rc));
@@ -1174,11 +1176,11 @@ int daos_connect(
11741176

11751177
/* try to open it again */
11761178
if (dst_cont_passed && !is_uuid) {
1177-
rc = daos_cont_open(*poh, *cont, DAOS_COO_RW, coh, &co_info, NULL);
1179+
rc = daos_cont_open(*poh, *cont, cont_open_flags, coh, &co_info, NULL);
11781180
} else {
11791181
char cont_str[130];
11801182
uuid_unparse(da->dst_cont_uuid, cont_str);
1181-
rc = daos_cont_open(*poh, cont_str, DAOS_COO_RW, coh, &co_info, NULL);
1183+
rc = daos_cont_open(*poh, cont_str, cont_open_flags, coh, &co_info, NULL);
11821184
}
11831185
if (rc != 0) {
11841186
MFU_LOG(MFU_LOG_ERR, "Failed to open container: "DF_RC, DP_RC(rc));
@@ -1572,7 +1574,23 @@ int daos_setup(
15721574
/* Check if containers are in the same pool */
15731575
bool same_pool = (strcmp(da->src_pool, da->dst_pool) == 0);
15741576

1575-
bool connect_pool = true;
1577+
/* Only need W on pools if creating a container */
1578+
unsigned int src_pool_connect_flags = DAOS_PC_RO;
1579+
unsigned int dst_pool_connect_flags = DAOS_PC_RO;
1580+
if (!dst_cont_passed) {
1581+
/* Need to create container */
1582+
dst_pool_connect_flags = DAOS_PC_RW;
1583+
}
1584+
if (same_pool) {
1585+
src_pool_connect_flags = dst_pool_connect_flags;
1586+
}
1587+
1588+
/* For POSIX containers, the source only needs read, but the destination needs read and write.
1589+
* For DAOS (object-level), both containers need read and write.
1590+
* Open the source with RO first, then elevate to RW if needed below. */
1591+
unsigned int src_cont_open_flags = DAOS_COO_RO;
1592+
unsigned int dst_cont_open_flags = DAOS_COO_RW;
1593+
15761594
bool create_cont = false;
15771595
bool require_new_cont = false;
15781596
bool preserve = false;
@@ -1589,26 +1607,50 @@ int daos_setup(
15891607
}
15901608
tmp_rc = daos_connect(rank, da, &da->src_pool, &da->src_cont,
15911609
&da->src_poh, &da->src_coh, false,
1592-
connect_pool, create_cont, require_new_cont,
1610+
true, src_pool_connect_flags, create_cont, src_cont_open_flags, require_new_cont,
15931611
preserve, mfu_src_file, dst_cont_passed);
15941612
if (tmp_rc != 0) {
15951613
/* tmp_rc from daos_connect is collective */
15961614
local_daos_error = true;
15971615
goto out;
15981616
}
15991617
/* Get the container type */
1600-
tmp_rc = daos_get_cont_type(da->src_coh, &da->src_cont_type);
1618+
tmp_rc = mfu_daos_get_cont_type(da->src_coh, &da->src_cont_type);
16011619
if (tmp_rc != 0) {
16021620
/* ideally, this should be the same for each process */
16031621
local_daos_error = true;
16041622
goto out;
16051623
}
16061624
/* Set the src api based on the container type */
1607-
tmp_rc = daos_set_api_cont_type(mfu_src_file, da->src_cont_type, da->api);
1625+
tmp_rc = mfu_daos_set_api_cont_type(mfu_src_file, da->src_cont_type, da->api);
16081626
if (tmp_rc != 0) {
16091627
local_daos_error = true;
16101628
goto out;
16111629
}
1630+
/* If using the DAOS API, we need to elevate permissions to RW for creating a snapshot */
1631+
if (mfu_src_file->type = DAOS) {
1632+
MPI_Barrier(MPI_COMM_WORLD);
1633+
1634+
tmp_rc = daos_cont_close(da->src_coh, NULL);
1635+
if (tmp_rc != 0) {
1636+
local_daos_error = true;
1637+
goto out;
1638+
}
1639+
da->src_coh = DAOS_HDL_INVAL;
1640+
1641+
/* Re-open with RW */
1642+
src_cont_open_flags = DAOS_COO_RW;
1643+
tmp_rc = daos_connect(rank, da, &da->src_pool, &da->src_cont,
1644+
&da->src_poh, &da->src_coh, false,
1645+
true, src_pool_connect_flags, create_cont, src_cont_open_flags, require_new_cont,
1646+
preserve, mfu_src_file, dst_cont_passed);
1647+
if (tmp_rc != 0) {
1648+
/* tmp_rc from daos_connect is collective */
1649+
local_daos_error = true;
1650+
goto out;
1651+
}
1652+
}
1653+
16121654
/* Sanity check before we create a new container */
16131655
if (da->src_cont_type != DAOS_PROP_CO_LAYOUT_POSIX) {
16141656
if (strcmp(da->src_path, "/") != 0) {
@@ -1622,7 +1664,7 @@ int daos_setup(
16221664
}
16231665

16241666
/* If we're using the DAOS API, the destination container cannot
1625-
* exist already, unless overriden by allow_exist_dst_cont. */
1667+
* exist already, unless overridden by allow_exist_dst_cont. */
16261668
if (mfu_src_file->type != POSIX && mfu_src_file->type != DFS && !da->allow_exist_dst_cont) {
16271669
require_new_cont = true;
16281670
}
@@ -1663,33 +1705,33 @@ int daos_setup(
16631705
}
16641706
}
16651707
if (same_pool) {
1666-
connect_pool = false;
1708+
/* Use the same handle as the source */
16671709
tmp_rc = daos_connect(rank, da, &da->dst_pool, &da->dst_cont,
16681710
&da->src_poh, &da->dst_coh, false,
1669-
connect_pool, create_cont, require_new_cont,
1670-
preserve, mfu_src_file, dst_cont_passed);
1711+
false, src_pool_connect_flags, create_cont, src_cont_open_flags,
1712+
require_new_cont, preserve, mfu_src_file, dst_cont_passed);
16711713
} else {
1672-
connect_pool = true;
1714+
/* Connect to a different handle */
16731715
tmp_rc = daos_connect(rank, da, &da->dst_pool, &da->dst_cont,
16741716
&da->dst_poh, &da->dst_coh, false,
1675-
connect_pool, create_cont, require_new_cont,
1676-
preserve, mfu_src_file, dst_cont_passed);
1717+
true, dst_pool_connect_flags, create_cont, dst_cont_open_flags,
1718+
require_new_cont, preserve, mfu_src_file, dst_cont_passed);
16771719
}
16781720
if (tmp_rc != 0) {
16791721
/* tmp_rc from daos_connect is collective */
16801722
local_daos_error = true;
16811723
goto out;
16821724
}
16831725
/* Get the container type */
1684-
tmp_rc = daos_get_cont_type(da->dst_coh, &da->dst_cont_type);
1726+
tmp_rc = mfu_daos_get_cont_type(da->dst_coh, &da->dst_cont_type);
16851727
if (tmp_rc != 0) {
16861728
/* ideally, this should be the same for each process */
16871729
local_daos_error = true;
16881730
goto out;
16891731
}
16901732
if (have_dst) {
16911733
/* Set the dst api based on the container type */
1692-
tmp_rc = daos_set_api_cont_type(mfu_dst_file, da->dst_cont_type, da->api);
1734+
tmp_rc = mfu_daos_set_api_cont_type(mfu_dst_file, da->dst_cont_type, da->api);
16931735
if (tmp_rc != 0) {
16941736
local_daos_error = true;
16951737
goto out;

src/common/mfu_daos.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,9 @@ int daos_connect(
310310
daos_handle_t* coh,
311311
bool force_serialize,
312312
bool connect_pool,
313+
unsigned int pool_connect_flags,
313314
bool create_cont,
315+
unsigned int cont_open_flags,
314316
bool require_new_cont,
315317
bool preserve,
316318
mfu_file_t* mfu_src_file,

src/daos-serialize/daos-serialize.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ int main(int argc, char** argv)
155155

156156
tmp_rc = daos_connect(rank, daos_args, &daos_args->src_pool,
157157
&daos_args->src_cont, &daos_args->src_poh,
158-
&daos_args->src_coh, force_serialize, true,
159-
false, false, false, NULL, true);
158+
&daos_args->src_coh, force_serialize, true, DAOS_PC_RW,
159+
false, DAOS_COO_RW, false, false, NULL, true);
160160
if (tmp_rc != 0) {
161161
daos_fini();
162162
mfu_finalize();

0 commit comments

Comments
 (0)