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

Ft/collect bucket attributes #3

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 1 addition & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,14 @@ $ docker build -t scality/nfsd .

A configuration file must be provided, check the dbd and sproxyd urls and set the MYBUCKET shell var with the bucket name you want to be exported.

OWNER_DISPLAY_NAME and OWNER_ID must be set in order to be able to read back from S3 data written through NFS. This information should be retrieved using a curl command on an existing object in the bucket
```
$ curl http://127.0.0.1:9004/default/bucket/$MYBUCKET/existing_object
```


```
$ mkdir conf logs
$ MYBUCKET=mybucket
$ OWNER_DISPLAY_NAME=ABC
$ OWNER_ID=XYZ
$ cat >conf/scality-nfsd.conf <<EOF
SCALITY
{
dbd_url = "http://127.0.0.1:9004/default/bucket";
dbd_url = "http://127.0.0.1:9004";
sproxyd_url = "http://127.0.0.1:8181/proxy/arc";
}

Expand All @@ -74,8 +67,6 @@ EXPORT
FSAL {
Name = "SCALITY";
bucket = "$MYBUCKET";
owner_display_name = "$OWNER_DISPLAY_NAME";
owner_id = "$OWNER_ID";
}
}
EOF
Expand Down
63 changes: 52 additions & 11 deletions src/FSAL/FSAL_SCALITY/dbd_rest_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include "random.h"

#define DEFAULT_CONTENT_TYPE "application/octet-stream"
#define BUCKET_BASE_PATH "/default/bucket"
#define ATTRIBUTES_BASE_PATH "/default/attributes"

struct dbd_response {
long http_status;
Expand Down Expand Up @@ -63,6 +65,7 @@ dbd_response_free(dbd_response_t *response)

static dbd_response_t *
dbd_get(struct scality_fsal_export *export,
const char *base_path,
const char *object,
dbd_get_parameters_t *parameters) {

Expand Down Expand Up @@ -137,13 +140,13 @@ dbd_get(struct scality_fsal_export *export,

if (object) {
char *tmp = curl_easy_escape(curl, object, strlen(object));
pos = snprintf(url, sizeof(url), "%s/%s/%s",
export->module->dbd_url, export->bucket, tmp);
pos = snprintf(url, sizeof(url), "%s%s/%s/%s",
export->module->dbd_url, base_path, export->bucket, tmp);
free(tmp);
}
else {
pos = snprintf(url, sizeof(url), "%s/%s%s",
export->module->dbd_url, export->bucket, query_string);
pos = snprintf(url, sizeof(url), "%s%s/%s%s",
export->module->dbd_url, base_path, export->bucket, query_string);
}


Expand Down Expand Up @@ -254,7 +257,7 @@ dbd_lookup_object(struct scality_fsal_export *export,
dbd_response_t *response1 = NULL;
dbd_response_t *response2 = NULL;

response1 = dbd_get(export, prefix, NULL);
response1 = dbd_get(export, BUCKET_BASE_PATH, prefix, NULL);
if ( NULL == response1 )
goto end;

Expand All @@ -267,7 +270,7 @@ dbd_lookup_object(struct scality_fsal_export *export,
.maxkeys = 1
};

response2 = dbd_get(export, NULL, &parameters);
response2 = dbd_get(export, BUCKET_BASE_PATH, NULL, &parameters);
if ( NULL == response2 || response2->http_status != 200 )
goto end;

Expand Down Expand Up @@ -328,7 +331,7 @@ dbd_delete(struct scality_fsal_export *export,
}

char *tmp = curl_easy_escape(curl, object, strlen(object));
pos = snprintf(url, sizeof(url), "%s/%s/%s",
pos = snprintf(url, sizeof(url), "%s"BUCKET_BASE_PATH"/%s/%s",
export->module->dbd_url, export->bucket, tmp);
free(tmp);

Expand Down Expand Up @@ -430,7 +433,7 @@ dbd_dirents(struct scality_fsal_export* export,
.delimiter = S3_DELIMITER,
};

response = dbd_get(export, NULL, &parameters);
response = dbd_get(export, BUCKET_BASE_PATH, NULL, &parameters);
if ( NULL == response )
return -1;

Expand Down Expand Up @@ -547,6 +550,44 @@ dbd_readdir(struct scality_fsal_export* export,
return;
}

int
dbd_collect_bucket_attributes(struct scality_fsal_export *export)
{
int ret = 0;
dbd_response_t *response;
response = dbd_get(export, ATTRIBUTES_BASE_PATH, "", NULL);
if ( NULL != response && 200 == response->http_status ) {
json_t *js_owner = json_object_get(response->body, "owner");
json_t *js_owner_display_name = json_object_get(response->body, "ownerDisplayName");
const char *owner = NULL,
*owner_display_name = NULL;
if (js_owner)
owner = json_string_value(js_owner);
if (js_owner_display_name)
owner_display_name = json_string_value(js_owner_display_name);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, why do you only care about the owner name and display name? Are the aws style acl's irrelevant in this context? How is authorization handled?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this stage of development, the ACLs are not yet integrated to NFS. Object created through NFS are assigned to the bucket owner and no authentication is done

if ( NULL != owner && NULL != owner_display_name ) {
export->owner_id = strdup(owner);
export->owner_display_name = strdup(owner_display_name);
if (NULL == export->owner_id || NULL == export->owner_display_name)
ret = -1;
}
else {
LogCrit(COMPONENT_FSAL,
"dbd_collect_bucket_attributes(%s) missing owner information",
export->bucket);
ret = -1;
}
}
else {
LogCrit(COMPONENT_FSAL,
"dbd_collect_bucket_attributes(%s) request failed",
export->bucket);
ret = -1;
}
dbd_response_free(response);
return ret;
}

static int
dbd_getattr_directory(struct scality_fsal_export* export,
struct scality_fsal_obj_handle *object_hdl)
Expand All @@ -566,7 +607,7 @@ dbd_getattr_directory(struct scality_fsal_export* export,
.maxkeys = 1
};
dbd_response_t *response = NULL;
response = dbd_get(export, NULL, &parameters);
response = dbd_get(export, BUCKET_BASE_PATH, NULL, &parameters);
if ( NULL != response && response->http_status == 200 ) {

json_t *commonPrefixes = json_object_get(response->body, "CommonPrefixes");
Expand Down Expand Up @@ -620,7 +661,7 @@ dbd_getattr_regular_file(struct scality_fsal_export* export,
{
int ret = 0;
dbd_response_t *response = NULL;
response = dbd_get(export, object_hdl->object ,NULL);
response = dbd_get(export, BUCKET_BASE_PATH, object_hdl->object ,NULL);
if ( NULL == response ) {
ret = -1;
goto out;
Expand Down Expand Up @@ -934,7 +975,7 @@ dbd_post(struct scality_fsal_export* export,
.size = strlen(payload)
};
char *tmp = curl_easy_escape(curl, object_hdl->object, strlen(object_hdl->object));
snprintf(url, sizeof(url), "%s/%s/%s",
snprintf(url, sizeof(url), "%s"BUCKET_BASE_PATH"/%s/%s",
export->module->dbd_url, export->bucket, tmp);
free(tmp);
curl_easy_setopt(curl, CURLOPT_URL, url);
Expand Down
3 changes: 3 additions & 0 deletions src/FSAL/FSAL_SCALITY/dbd_rest_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ int
dbd_getattr(struct scality_fsal_export* export,
struct scality_fsal_obj_handle *object_hdl);

int
dbd_collect_bucket_attributes(struct scality_fsal_export *export);

int
dbd_delete(struct scality_fsal_export *export,
const char *object);
Expand Down
4 changes: 0 additions & 4 deletions src/FSAL/FSAL_SCALITY/export.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,6 @@ static struct config_item export_params[] = {
CONF_ITEM_NOOP("name"),
CONF_MAND_STR("bucket", 1, MAXPATHLEN, NULL,
scality_fsal_export, bucket),
CONF_MAND_STR("owner_display_name", 1, MAXPATHLEN, NULL,
scality_fsal_export, owner_display_name),
CONF_MAND_STR("owner_id", 1, MAXPATHLEN, NULL,
scality_fsal_export, owner_id),
CONFIG_EOL
};

Expand Down
7 changes: 7 additions & 0 deletions src/FSAL/FSAL_SCALITY/handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,13 @@ fsal_status_t scality_lookup_path(struct fsal_export *exp_hdl,
if ( 0 == ret )
handle_keyp = handle_key;

ret = dbd_collect_bucket_attributes(myself);
if ( 0 != ret ) {
LogCrit(COMPONENT_FSAL,
"Cannot collect bucket attributes for %s",
myself->export_path);
return fsalstat(ERR_FSAL_NOENT, ENOENT);
}
myself->root_handle =
alloc_handle(object,
handle_keyp,
Expand Down
2 changes: 1 addition & 1 deletion src/config_samples/scality.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

SCALITY
{
dbd_url = "http://127.0.0.1:9004/default/bucket";
dbd_url = "http://127.0.0.1:9004";
sproxyd_url = "http://127.0.0.1:81/proxy/arc";
}

Expand Down