Permalink
Browse files

Added capabilities

  • Loading branch information...
1 parent 7add25d commit 56ec2f4ce73dea9b96f5c507b904ce33f5d68320 @koenbollen committed Jul 9, 2010
Showing with 231 additions and 31 deletions.
  1. +96 −8 src/cdmi.c
  2. +7 −2 src/cdmi.h
  3. +76 −1 src/cdmifs.c
  4. +3 −0 src/common.h
  5. +21 −0 src/fs/attr.c
  6. +1 −0 src/fs/attr.h
  7. +4 −1 src/fs/control.c
  8. +20 −18 src/mime.h
  9. +3 −1 src/net.c
View
@@ -70,6 +70,15 @@ int cdmi_get( cdmi_request_t *request, const char *path )
cdmitype = CDMI_DATAOBJECT;
}
}
+ else if( ISSET(flags, CDMI_CAPABILITIES) )
+ {
+ assert( request->cdmi == 1 );
+ if( cdmitype != CDMI_CAPABILITIES )
+ {
+ headers = slist_replace( headers, "Accept: %s", mime[M_CAPABILITIES] );
+ cdmitype = CDMI_CAPABILITIES;
+ }
+ }
else if( cdmitype != 0 )
{
headers = slist_replace( headers, "Accept: %s", mime[M_OBJECT] );
@@ -94,7 +103,11 @@ int cdmi_get( cdmi_request_t *request, const char *path )
/* Build the url from the path and append the field
* to it.
*/
- url = path2url( path );
+ if( ISSET(flags, CDMI_NORESOLVE) )
+ url = path2unresolved( path );
+ else
+ url = path2url( path );
+
urlsize = strlen( url ) + 1;
if( request->fields != NULL )
for( cpp = request->fields, cp = *cpp; *cpp; cpp++, cp = *cpp )
@@ -116,7 +129,6 @@ int cdmi_get( cdmi_request_t *request, const char *path )
}
}
-
/* Set url to the curl object, download the data and
* do error checks.
*/
@@ -128,7 +140,7 @@ int cdmi_get( cdmi_request_t *request, const char *path )
request->rawdata = download( curl );
if( !request->rawdata )
return -1;
- /*puts( data );
+ /*puts( request->rawdata );
*/
errno = 0;
@@ -142,7 +154,7 @@ int cdmi_get( cdmi_request_t *request, const char *path )
res = curl_easy_getinfo( curl, CURLINFO_CONTENT_TYPE, &(request->contenttype) );
if( res != CURLE_OK || request->contenttype == NULL )
- return -1;
+ return rerrno( EPROTO );
if( request->cdmi )
{
if( cdmitype == CDMI_CONTAINER && strcmp( request->contenttype, mime[M_CONTAINER] ) != 0 )
@@ -243,7 +255,7 @@ int cdmi_put( cdmi_request_t *request, const char *path )
}
#ifndef NDEBUG
- if( request->type != MOVE )
+ if( request->root == NULL && request->type != MOVE )
{
assert( ISSET(flags, CDMI_CONTAINER) || ISSET(flags, CDMI_DATAOBJECT) );
assert( request->cdmi == 0 ); /* only supported */
@@ -293,7 +305,15 @@ int cdmi_put( cdmi_request_t *request, const char *path )
json_decref( root );
data = realloc( data, strlen(data)+2 );
strcat( data, "\n" );
- puts( data );
+ headers = slist_replace( headers, "Expect:" );
+ }
+ else if( request->root != NULL )
+ {
+ data = json_dumps( request->root, JSON_INDENT(1) );
+ data = realloc( data, strlen(data)+2 );
+ strcat( data, "\n" );
+ /*puts( data );
+ */
headers = slist_replace( headers, "Expect:" );
}
}
@@ -344,7 +364,15 @@ int cdmi_put( cdmi_request_t *request, const char *path )
json_decref( root );
data = realloc( data, strlen(data)+2 );
strcat( data, "\n" );
- puts( data );
+ headers = slist_replace( headers, "Expect:" );
+ }
+ else if( request->root != NULL )
+ {
+ data = json_dumps( request->root, JSON_INDENT(1) );
+ data = realloc( data, strlen(data)+2 );
+ strcat( data, "\n" );
+ /*puts( data );
+ */
headers = slist_replace( headers, "Expect:" );
}
}
@@ -435,6 +463,34 @@ void cdmi_free( cdmi_request_t *request )
json_decref( request->root );
}
+
+json_t *getcapabilities( const char *path )
+{
+ int ret;
+ char url[512] = "/cdmi_capabilities/";
+ if( path != NULL )
+ {
+ if( path[0] == '/' )
+ path++;
+ strcat( url, path );
+ }
+ cdmi_request_t req;
+
+ req.type = GET;
+ req.cdmi = 1;
+ req.fields = (char*[]){ "capabilities", NULL };
+ req.flags = CDMI_CAPABILITIES | CDMI_SINGLE | CDMI_CHECK | CDMI_NORESOLVE;
+ ret = cdmi_get( &req, url );
+ if( ret == -1 || req.root == NULL )
+ {
+ return NULL;
+ }
+
+ json_t *capa = req.root;
+ json_incref( capa );
+ cdmi_free( &req );
+ return capa;
+}
json_t *getmetadata( const char *path )
{
int ret;
@@ -449,7 +505,26 @@ json_t *getmetadata( const char *path )
ret = cdmi_get( &request, path );
if( ret == -1 )
return NULL;
- return request.root;
+ json_t *metadata = request.root;
+ json_incref( metadata );
+ cdmi_free( &request );
+ return metadata;
+}
+
+int setmetadata( const char *path, json_t *metadata )
+{
+ int ret;
+
+ cdmi_request_t req;
+ req.type = PUT;
+ req.flags = CDMI_DATAOBJECT;
+ req.cdmi = 1;
+ req.root = json_object();
+ json_object_set( req.root, "metadata", metadata );
+ ret = cdmi_put( &req, path );
+ cdmi_free( &req );
+
+ return ret;
}
char *path2url( const char *path )
@@ -465,6 +540,19 @@ char *path2url( const char *path )
return url;
}
+char *path2unresolved( const char *path )
+{
+ static char url[URLSIZE+1];
+ if( path[0] == '/' )
+ path++;
+ snprintf( url, URLSIZE, "%s://%s:%s/%s",
+ options.ssl?"https":"http",
+ options.host, options.port,
+ path
+ );
+ return url;
+}
+
char *path2path( const char *path )
{
static char url[URLSIZE+1];
View
@@ -15,11 +15,13 @@
-#define CDMI_CONTAINER (1<<1)
-#define CDMI_DATAOBJECT (1<<2)
+#define CDMI_CONTAINER (1<<1)
+#define CDMI_DATAOBJECT (1<<2)
+#define CDMI_CAPABILITIES (1<<5)
#define CDMI_SINGLE (1<<3)
#define CDMI_CHECK (1<<4)
+#define CDMI_NORESOLVE (1<<6)
typedef enum _cdmi_request_type
{
@@ -60,9 +62,12 @@ extern int cdmi_put( cdmi_request_t *request, const char *path );
extern int cdmi_delete( cdmi_request_t *request, const char *path );
extern void cdmi_free( cdmi_request_t *request );
+extern json_t *getcapabilities( const char *path );
extern json_t *getmetadata( const char *path );
+extern int setmetadata( const char *path, json_t *metadata );
extern char *path2url( const char *path );
+extern char *path2unresolved( const char *path );
extern char *path2path( const char *path );
extern int response_code2errno( long response_code );
extern objectid_t objectid_decode( const char *b64data );
View
@@ -5,6 +5,7 @@
#include "common.h"
#include <assert.h>
+#include <errno.h>
#include <fuse.h>
#include <fuse_opt.h>
#include <stdio.h>
@@ -16,6 +17,7 @@
#include "net.h"
#include "util.h"
+#include "cdmi.h"
#include "fs/attr.h"
#include "fs/control.h"
@@ -25,6 +27,7 @@
static int parse_uri();
static int cdmifs_opt_proc( void *data, const char *arg, int key, struct fuse_args *outargs );
+static void cdmifs_capabilities();
#if FUSE_VERSION >= 26
static void *cdmifs_init(struct fuse_conn_info *conn);
#else
@@ -46,7 +49,8 @@ struct fuse_operations cdmifs_operations = {
.truncate = cdmifs_truncate,
.unlink = cdmifs_unlink,
.utimens = cdmifs_utimens,
- .rename = cdmifs_rename
+ .rename = cdmifs_rename,
+ .chmod = cdmifs_chmod
};
struct options options;
@@ -96,6 +100,8 @@ static void *cdmifs_init(void)
DEBUGV( " root: %s\n", options.root );
DEBUGV( " user: %s\n", options.username );
+ cdmifs_capabilities();
+
curl_global_init( CURL_GLOBAL_ALL );
return NULL;
@@ -184,4 +190,73 @@ static int cdmifs_opt_proc( void *data, const char *arg, int key, struct fuse_ar
}
}
+static void cdmifs_capabilities()
+{
+ json_t *capa;
+ options.gotmeta = 1;
+
+ capa = getcapabilities(NULL);
+ if( capa == NULL )
+ {
+ fprintf( stderr, "error: unable to fetch capabilities: %s\n", strerror(errno) );
+ exit(1);
+ }
+ if( !json_is_true( json_object_get(capa, "cdmi_size") ) )
+ {
+ fprintf( stderr, "error: server doesn't support: cdmi_size\n" );
+ exit(1);
+ }
+ json_decref(capa);
+
+ capa = getcapabilities("/container/");
+ if( capa == NULL )
+ {
+ fprintf( stderr, "error: unable to fetch capabilities: %s\n", strerror(errno) );
+ exit(1);
+ }
+ if( !json_is_true( json_object_get(capa, "cdmi_list_children") ) ||
+ !json_is_true( json_object_get(capa, "cdmi_list_children_range") ) ||
+ !json_is_true( json_object_get(capa, "cdmi_create_container") ) ||
+ !json_is_true( json_object_get(capa, "cdmi_delete_container") ) ||
+ !json_is_true( json_object_get(capa, "cdmi_read_metadata") ) ||
+ !json_is_true( json_object_get(capa, "cdmi_move_container") ) )
+ {
+ fprintf( stderr, "error: server doesn't fully support: containers\n" );
+ exit(1);
+ }
+ if( !json_is_true( json_object_get(capa, "cdmi_modify_metadata") ) )
+ {
+ options.gotmeta = 0;
+ }
+ json_decref(capa);
+
+
+ capa = getcapabilities("/dataobject/");
+ if( capa == NULL )
+ {
+ fprintf( stderr, "error: unable to fetch capabilities: %s\n", strerror(errno) );
+ exit(1);
+ }
+ if( !json_is_true( json_object_get(capa, "cdmi_read_value") ) ||
+ !json_is_true( json_object_get(capa, "cdmi_read_value_range") ) ||
+ !json_is_true( json_object_get(capa, "cdmi_modify_value") ) ||
+ !json_is_true( json_object_get(capa, "cdmi_modify_value_range") ) ||
+ !json_is_true( json_object_get(capa, "cdmi_read_metadata") ) ||
+ !json_is_true( json_object_get(capa, "cdmi_delete_dataobject") ) )
+ {
+ fprintf( stderr, "error: server doesn't fully support: dataobject\n" );
+ exit(1);
+ }
+ if( !json_is_true( json_object_get(capa, "cdmi_modify_metadata") ) )
+ {
+ options.gotmeta = 0;
+ }
+ json_decref(capa);
+
+ if( options.gotmeta != 1 )
+ {
+ fprintf( stderr, "warning: unable to store permissions\n" );
+ }
+
+}
View
@@ -37,6 +37,9 @@ struct options
int debug;
int curl_debug;
+
+
+ int gotmeta;
};
extern struct options options;
View
@@ -127,9 +127,30 @@ static int parse_metadata( json_t *metadata, struct stat *stbuf )
);
}
+ if( options.gotmeta && json_is_string( json_object_get(metadata, "cdmifs_mode") ) )
+ {
+ const char *modestr = json_string_value( json_object_get(metadata, "cdmifs_mode" ) );
+ sscanf( modestr, "%o", &(stbuf->st_mode) );
+ }
+
return 0;
}
+int cdmifs_chmod( const char *path, mode_t mode )
+{
+ if( !options.gotmeta )
+ return -ENOSYS;
+ int ret;
+ char modestr[16];
+ sprintf( modestr, "0%o", mode );
+ json_t *meta = json_object();
+ json_object_set( meta, "cdmifs_mode", json_string(modestr) );
+ ret = setmetadata( path, meta );
+ json_decref( meta );
+ if( ret != 1 )
+ return errno;
+ return 0;
+}
int cdmifs_utimens( const char *path, const struct timespec tv[2] )
{
View
@@ -12,6 +12,7 @@ extern int cdmifs_getattr(
struct stat *stbuf
);
+extern int cdmifs_chmod( const char *path, mode_t mode );
extern int cdmifs_utimens( const char *path, const struct timespec tv[2] );
#endif /* !ATTR_H */
View
@@ -9,6 +9,7 @@
#include "../common.h"
#include "../net.h"
#include "../util.h"
+#include "attr.h"
#include <errno.h>
#include <fcntl.h>
@@ -77,7 +78,9 @@ int cdmifs_create(
struct fuse_file_info *fi
)
{
- return cdmifs_common( path, mode, fi );
+ int ret = cdmifs_common( path, mode, fi );
+ cdmifs_chmod( path, mode );
+ return ret;
}
int cdmifs_release(
Oops, something went wrong.

0 comments on commit 56ec2f4

Please sign in to comment.