Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DAOS-14698 crtl: Create container with attributes #15300

Merged
merged 41 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
5fcd159
DAOS-14698 crtl: Create container with attributes
kanard38 Oct 9, 2024
315f440
DAOS-14698 crtl: Create container with attributes
kanard38 Oct 9, 2024
865f2e5
DAOS-14698 crtl: Create container with attributes
kanard38 Oct 9, 2024
4dd51bd
Merge remote-tracking branch 'origin/master' into ckochhof/dev/master…
kanard38 Oct 22, 2024
819b856
DAOS-14698 crtl: Create container with attributes
kanard38 Oct 9, 2024
b922f70
DAOS-14698 crtl: Create container with attributes
kanard38 Oct 9, 2024
825512d
Merge remote-tracking branch 'origin/master' into ckochhof/dev/master…
kanard38 Oct 23, 2024
2e9afbd
DAOS-14698 crtl: Create container with attributes
kanard38 Oct 9, 2024
2d26f4d
Merge remote-tracking branch 'origin/master' into ckochhof/dev/master…
kanard38 Oct 23, 2024
055c3a0
DAOS-14698 crtl: Create container with attributes
kanard38 Oct 9, 2024
a3d0a02
Merge remote-tracking branch 'origin/master' into ckochhof/dev/master…
kanard38 Oct 24, 2024
7f26733
DAOS-14698 crtl: Create container with attributes
kanard38 Oct 9, 2024
5e72550
Merge remote-tracking branch 'origin/master' into ckochhof/dev/master…
kanard38 Oct 25, 2024
5dca3b4
Merge remote-tracking branch 'origin/master' into ckochhof/dev/master…
kanard38 Oct 25, 2024
98bd3c2
Merge remote-tracking branch 'origin/master' into ckochhof/dev/master…
kanard38 Oct 28, 2024
a390e8a
DAOS-14698 crtl: Create container with attributes
kanard38 Oct 9, 2024
9af9320
Merge remote-tracking branch 'origin/master' into ckochhof/dev/master…
kanard38 Oct 29, 2024
d2ee639
DAOS-14698 crtl: Create container with attributes
kanard38 Oct 9, 2024
90186bc
Merge remote-tracking branch 'origin/master' into ckochhof/dev/master…
kanard38 Nov 4, 2024
0561a5b
DAOS-14698 crtl: Create container with attributes
kanard38 Oct 9, 2024
263168f
DAOS-14698 crtl: Create container with attributes
kanard38 Oct 9, 2024
436436f
DAOS-14698 crtl: Create container with attributes
kanard38 Oct 9, 2024
f30184d
Merge remote-tracking branch 'origin/master' into ckochhof/dev/master…
kanard38 Nov 5, 2024
b1aaa8f
Merge remote-tracking branch 'origin/master' into ckochhof/dev/master…
kanard38 Nov 15, 2024
af54e76
DAOS-14698 crtl: Create container with attributes
kanard38 Nov 5, 2024
d230c87
DAOS-14698 crtl: Create container with attributes
kanard38 Nov 5, 2024
e3f510d
DAOS-14698 crtl: Create container with attributes
kanard38 Nov 5, 2024
2cb2ddd
DAOS-14698 crtl: Create container with attributes
kanard38 Nov 5, 2024
3711ee9
DAOS-14698 crtl: Create container with attributes
kanard38 Nov 5, 2024
a4197e1
Merge remote-tracking branch 'origin/master' into ckochhof/dev/master…
kanard38 Nov 20, 2024
7c0cf9a
Merge remote-tracking branch 'origin/master' into ckochhof/dev/master…
kanard38 Nov 21, 2024
4e323bd
DAOS-14698 crtl: Create container with attributes
kanard38 Nov 5, 2024
7ef67b6
DAOS-14698 crtl: Create container with attributes
kanard38 Nov 5, 2024
0b17fe6
DAOS-14698 crtl: Create container with attributes
kanard38 Nov 5, 2024
34614ba
Merge remote-tracking branch 'origin/master' into ckochhof/dev/master…
kanard38 Nov 26, 2024
0afbeac
Merge remote-tracking branch 'origin/master' into ckochhof/dev/master…
kanard38 Nov 28, 2024
d5a474a
DAOS-14698 crtl: Create container with attributes
kanard38 Nov 5, 2024
5264e23
Merge remote-tracking branch 'origin/master' into ckochhof/dev/master…
kanard38 Dec 4, 2024
a8d3da6
Merge remote-tracking branch 'origin/master' into ckochhof/dev/master…
kanard38 Dec 5, 2024
61c000a
Merge remote-tracking branch 'origin/master' into ckochhof/dev/master…
kanard38 Dec 6, 2024
a90bf29
Merge remote-tracking branch 'origin/master' into ckochhof/dev/master…
kanard38 Dec 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci/unit/test_nlt_node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ pip install /opt/daos/lib/daos/python/
sudo prlimit --nofile=1024:262144 --pid $$
prlimit -n

./utils/node_local_test.py --max-log-size 1700MiB --dfuse-dir /localhome/jenkins/ \
./utils/node_local_test.py --max-log-size 1900MiB --dfuse-dir /localhome/jenkins/ \
--log-usage-save nltir.xml --log-usage-export nltr.json all
99 changes: 70 additions & 29 deletions src/client/dfs/duns.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright 2019-2023 Intel Corporation.
* (C) Copyright 2019-2024 Intel Corporation.
*
* SPDX-License-Identifier: BSD-2-Clause-Patent
*/
Expand Down Expand Up @@ -1131,18 +1131,20 @@ duns_create_path(daos_handle_t poh, const char *path, struct duns_attr_t *attrp)
int
duns_link_cont(daos_handle_t poh, const char *cont, const char *path)
{
daos_handle_t coh;
daos_prop_t *prop;
struct daos_prop_entry *entry;
daos_pool_info_t pinfo = {0};
daos_cont_info_t cinfo = {0};
daos_cont_layout_t type;
char pool_str[DAOS_UUID_STR_SIZE];
char cont_str[DAOS_UUID_STR_SIZE];
int len;
char str[DUNS_MAX_XATTR_LEN];
char type_str[10];
int rc, rc2;
daos_handle_t coh;
daos_prop_t *prop;
struct daos_prop_entry *entry;
daos_pool_info_t pinfo = {0};
daos_cont_info_t cinfo = {0};
daos_cont_layout_t type;
char pool_str[DAOS_UUID_STR_SIZE];
char cont_str[DAOS_UUID_STR_SIZE];
int len;
char str[DUNS_MAX_XATTR_LEN];
char type_str[10];
bool backend_dfuse = false;
int rc2;
int rc;

if (path == NULL) {
D_ERROR("Invalid path\n");
Expand All @@ -1155,7 +1157,7 @@ duns_link_cont(daos_handle_t poh, const char *cont, const char *path)
return daos_der2errno(rc);
}

rc = daos_cont_open(poh, cont, DAOS_COO_RO, &coh, &cinfo, NULL);
rc = daos_cont_open(poh, cont, DAOS_COO_RW, &coh, &cinfo, NULL);
if (rc) {
D_ERROR("daos_cont_open() failed "DF_RC"\n", DP_RC(rc));
return daos_der2errno(rc);
Expand Down Expand Up @@ -1203,7 +1205,6 @@ duns_link_cont(daos_handle_t poh, const char *cont, const char *path)
D_FREE(dir);
D_GOTO(out_cont, rc = err);
}
D_FREE(dir);
#ifdef LUSTRE_INCLUDE
if (fs.f_type == LL_SUPER_MAGIC) {
rc = duns_link_lustre_path(pool_str, cont_str, type, path, mode);
Expand All @@ -1218,28 +1219,46 @@ duns_link_cont(daos_handle_t poh, const char *cont, const char *path)
if (rc == -1) {
rc = errno;
D_ERROR("Failed to create dir %s: %d (%s)\n", path, rc, strerror(rc));
D_FREE(dir);
D_GOTO(out_cont, rc);
}

/* Open the parent directory for the new container so we can call a dfuse iotcl
* to discover the user running dfuse.
*/
if (fs.f_type == FUSE_SUPER_MAGIC) {
struct stat finfo;
/*
* This next stat will cause dfuse to lookup the entry point and perform a
* container connect, therefore this data will be read from root of the new
* container, not the directory.
*
* TODO: This could call getxattr to verify success.
*/
rc = stat(path, &finfo);
if (rc) {
rc = errno;
D_ERROR("Failed to access container: %d (%s)\n", rc, strerror(rc));
int fd;
struct dfuse_user_reply dur = {};

fd = open(dirp, O_RDONLY | O_DIRECTORY | O_NOFOLLOW);
if (fd == -1) {
int err = errno;

DS_ERROR(err, "Dfuse open failed '%s", dirp);
D_FREE(dir);
D_GOTO(err_link, err);
}

rc = ioctl(fd, DFUSE_IOCTL_DFUSE_USER, &dur);
close(fd);
if (rc == -1) {
int err = errno;

DS_ERROR(err, "Dfuse ioctl failed %s", dirp);
D_FREE(dir);
D_GOTO(err_link, err);
}

rc = duns_set_fuse_acl(dur.uid, coh);
if (rc != -DER_SUCCESS) {
DS_ERROR(rc, "Dfuse set acl failed %s", dirp);
D_FREE(dir);
D_GOTO(err_link, rc);
}

backend_dfuse = true;
}
D_FREE(dir);
} else if (type != DAOS_PROP_CO_LAYOUT_UNKNOWN) {
/** create a new file for other container types */
int fd;
Expand Down Expand Up @@ -1304,11 +1323,33 @@ duns_link_cont(daos_handle_t poh, const char *cont, const char *path)
}
D_GOTO(err_link, rc);
}
if (backend_dfuse) {
struct stat finfo;
/*
* This next stat will cause dfuse to lookup the entry point and perform a
* container connect, therefore this data will be read from root of the new
* container, not the directory.
*
* TODO: This could call getxattr to verify success.
*/
rc = stat(path, &finfo);
if (rc) {
rc = errno;
DS_ERROR(rc, "Failed to access container bind at '%s'", path);
goto err_link;
}
}

out_cont:
rc2 = daos_cont_close(coh, NULL);
if (rc == 0)
rc = rc2;
if (rc2 != -DER_SUCCESS) {
DL_ERROR(rc2, "failed to close container");
if (rc2 == -DER_NOMEM)
/* Second close to properly handle fault injection */
daos_cont_close(coh, NULL);
else if (rc == -DER_SUCCESS)
rc = daos_der2errno(rc2);
}
return rc;
err_link:
if (type == DAOS_PROP_CO_LAYOUT_POSIX)
Expand Down
101 changes: 36 additions & 65 deletions src/control/cmd/daos/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ type containerCreateCmd struct {
Mode ConsModeFlag `long:"mode" short:"M" description:"DFS consistency mode"`
ACLFile string `long:"acl-file" short:"A" description:"input file containing ACL"`
Group ui.ACLPrincipalFlag `long:"group" short:"g" description:"group who will own the container (group@[domain])"`
Attrs ui.SetPropertiesFlag `long:"attrs" short:"a" description:"user-defined attributes (key:val[,key:val...])"`
Args struct {
Label string `positional-arg-name:"label"`
} `positional-args:"yes"`
Expand Down Expand Up @@ -305,11 +306,7 @@ func (cmd *containerCreateCmd) Execute(_ []string) (err error) {
defer disconnectPool()

var contID string
if cmd.Path != "" {
contID, err = cmd.contCreateUNS()
} else {
contID, err = cmd.contCreate()
}
contID, err = cmd.contCreate()
if err != nil {
return err
}
Expand Down Expand Up @@ -397,76 +394,50 @@ func (cmd *containerCreateCmd) contCreate() (string, error) {
if err != nil {
return "", err
}
contID := cmd.contUUID.String()
cContID := C.CString(contID)
defer freeString(cContID)

var contID string
if cmd.contUUID == uuid.Nil {
contID = cmd.contLabel
} else {
contID = cmd.contUUID.String()
}

cmd.Infof("Successfully created container %s", contID)
return contID, nil
}

func (cmd *containerCreateCmd) contCreateUNS() (string, error) {
var dattr C.struct_duns_attr_t

props, cleanupProps, err := cmd.getCreateProps()
if err != nil {
return "", err
cleanupContainer := func() {
rc := C.daos_cont_destroy(cmd.cPoolHandle, cContID, goBool2int(true), nil)
if err := daosError(rc); err != nil {
cmd.Noticef("Failed to clean-up container %v", err)
mjmac marked this conversation as resolved.
Show resolved Hide resolved
}
}
defer cleanupProps()
dattr.da_props = props

if !cmd.Type.Set {
return "", errors.New("container type is required for UNS")
}
dattr.da_type = cmd.Type.Type
if len(cmd.Attrs.ParsedProps) != 0 {
kjacque marked this conversation as resolved.
Show resolved Hide resolved
attrs := make(attrList, 0, len(cmd.Attrs.ParsedProps))
for key, val := range cmd.Attrs.ParsedProps {
attrs = append(attrs, &attribute{
Name: key,
Value: []byte(val),
})
}

if cmd.poolUUID != uuid.Nil {
poolUUIDStr := C.CString(cmd.poolUUID.String())
defer freeString(poolUUIDStr)
C.uuid_parse(poolUUIDStr, &dattr.da_puuid[0])
}
if cmd.contUUID != uuid.Nil {
contUUIDStr := C.CString(cmd.contUUID.String())
defer freeString(contUUIDStr)
C.uuid_parse(contUUIDStr, &dattr.da_cuuid[0])
}
if err := cmd.openContainer(C.DAOS_COO_RW); err != nil {
cleanupContainer()
return "", errors.Wrapf(err, "failed to open new container %s", contID)
}
defer cmd.closeContainer()

if cmd.ChunkSize.Set {
mjmac marked this conversation as resolved.
Show resolved Hide resolved
dattr.da_chunk_size = cmd.ChunkSize.Size
}
if cmd.ObjectClass.Set {
dattr.da_oclass_id = cmd.ObjectClass.Class
}
if cmd.DirObjectClass.Set {
dattr.da_dir_oclass_id = cmd.DirObjectClass.Class
}
if cmd.FileObjectClass.Set {
dattr.da_file_oclass_id = cmd.FileObjectClass.Class
}
if cmd.CHints != "" {
hint := C.CString(cmd.CHints)
defer freeString(hint)
C.strncpy(&dattr.da_hints[0], hint, C.DAOS_CONT_HINT_MAX_LEN-1)
if err := setDaosAttributes(cmd.cContHandle, contAttr, attrs); err != nil {
cleanupContainer()
return "", errors.Wrapf(err, "failed to set user attributes on new container %s", contID)
}
}

cPath := C.CString(cmd.Path)
defer freeString(cPath)
if cmd.Path != "" {
cPath := C.CString(cmd.Path)
defer freeString(cPath)

dunsErrno := C.duns_create_path(cmd.cPoolHandle, cPath, &dattr)
rc := C.daos_errno2der(dunsErrno)
if err := daosError(rc); err != nil {
return "", errors.Wrapf(err, "duns_create_path() failed")
dunsErrno := C.duns_link_cont(cmd.cPoolHandle, cContID, cPath)
rc := C.daos_errno2der(dunsErrno)
if err := daosError(rc); err != nil {
cleanupContainer()
return "", errors.Wrapf(err, "duns_link_cont() failed")
}
}

contID := C.GoString(&dattr.da_cont[0])
cmd.contUUID, err = uuid.Parse(contID)
if err != nil {
cmd.contLabel = contID
}
cmd.Infof("Successfully created container %s type %s", contID, cmd.Type.String())
return contID, nil
}
Expand Down
Loading
Loading