]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librgw: block in create bucket, rgw_mkdir
authorMatt Benjamin <mbenjamin@redhat.com>
Wed, 7 Oct 2015 21:19:29 +0000 (17:19 -0400)
committerMatt Benjamin <mbenjamin@redhat.com>
Fri, 12 Feb 2016 17:04:54 +0000 (12:04 -0500)
Unit test runs, doesn't...seem to create a bucket.

Signed-off-by: Matt Benjamin <mbenjamin@redhat.com>
src/rgw/rgw_file.cc
src/rgw/rgw_file.h
src/rgw/rgw_os_lib.cc
src/rgw/rgw_os_lib.h
src/test/librgw_file.cc

index 41878125d91c57c27ec9a38e07dad53660a37e06..e1502baccc0baff8effa75b29ef4376992475e12 100644 (file)
@@ -152,12 +152,18 @@ int rgw_mkdir(struct rgw_fs *rgw_fs,
     return rc;
   }
 
+  RGWLibFS *fs = static_cast<RGWLibFS*>(rgw_fs->fs_private);
+  CephContext* cct = static_cast<CephContext*>(rgw_fs->rgw);
+
   /* cannot create a bucket in a bucket */
   if (! is_root(uri)) {
     return EINVAL;
   }
 
-  /* TODO: implement */
+  RGWCreateBucketRequest req(cct, fs->get_user(), uri);
+  (void) librgw.get_fe()->execute_req(&req);
+
+  /* TODO: result */
 
   return 0;
 }
@@ -304,6 +310,8 @@ int rgw_readdir(struct rgw_fs *rgw_fs,
 
   }
 
+  /* TODO: result */
+
   *eof = true; // XXX move into RGGWListBucket(s)Request
 
   return 0;
index 150536b79608aa16a05990305faa50278e2dfe37..a699a714f462601de1c0fb41152b06c7638c8500 100644 (file)
@@ -172,4 +172,104 @@ public:
 
 }; /* RGWListBucketRequest */
 
+/*
+  create bucket
+*/
+
+class RGWCreateBucketRequest : public RGWLibRequest,
+                              public RGWCreateBucket_OS_Lib /* RGWOp */
+{
+public:
+  std::string& uri;
+
+  RGWCreateBucketRequest(CephContext* _cct, RGWUserInfo *_user,
+                       std::string& _uri)
+    : RGWLibRequest(_cct, _user), uri(_uri) {
+    magic = 73;
+    op = this;
+  }
+
+  virtual bool only_bucket() { return false; }
+
+  virtual int op_init() {
+    // assign store, s, and dialect_handler
+    RGWObjectCtx* rados_ctx
+      = static_cast<RGWObjectCtx*>(get_state()->obj_ctx);
+    // framework promises to call op_init after parent init
+    assert(rados_ctx);
+    RGWOp::init(rados_ctx->store, get_state(), this);
+    op = this; // assign self as op: REQUIRED
+    return 0;
+  }
+
+  virtual int header_init() {
+
+    struct req_state* s = get_state();
+    s->info.method = "PUT";
+    s->op = OP_PUT;
+
+    /* XXX derp derp derp */
+    s->relative_uri = uri;
+    s->info.request_uri = uri; // XXX
+    s->info.effective_uri = uri;
+    s->info.request_params = "";
+    s->info.domain = ""; /* XXX ? */
+
+    // woo
+    s->user = user;
+
+    return 0;
+  }
+}; /* RGWCreateBucketRequest */
+
+/*
+  delete bucket
+*/
+
+class RGWDeleteBucketRequest : public RGWLibRequest,
+                              public RGWDeleteBucket_OS_Lib /* RGWOp */
+{
+public:
+  std::string& uri;
+
+  RGWDeleteBucketRequest(CephContext* _cct, RGWUserInfo *_user,
+                       std::string& _uri)
+    : RGWLibRequest(_cct, _user), uri(_uri) {
+    magic = 74;
+    op = this;
+  }
+
+  virtual bool only_bucket() { return true; }
+
+  virtual int op_init() {
+    // assign store, s, and dialect_handler
+    RGWObjectCtx* rados_ctx
+      = static_cast<RGWObjectCtx*>(get_state()->obj_ctx);
+    // framework promises to call op_init after parent init
+    assert(rados_ctx);
+    RGWOp::init(rados_ctx->store, get_state(), this);
+    op = this; // assign self as op: REQUIRED
+    return 0;
+  }
+
+  virtual int header_init() {
+
+    struct req_state* s = get_state();
+    s->info.method = "DELETE";
+    s->op = OP_DELETE;
+
+    /* XXX derp derp derp */
+    s->relative_uri = uri;
+    s->info.request_uri = uri; // XXX
+    s->info.effective_uri = uri;
+    s->info.request_params = "";
+    s->info.domain = ""; /* XXX ? */
+
+    // woo
+    s->user = user;
+
+    return 0;
+  }
+}; /* RGWDeleteBucketRequest */
+
 #endif /* RGW_FILE_H */
index 963243386a37c29e087d3e94dce73b5bb806295c..8ae261272418407a2195d12d583c2342ba2fe28a 100644 (file)
@@ -121,3 +121,17 @@ void RGWListBucket_OS_Lib::send_response()
     req->operator()(iter.key.name, iter.key.name); // XXX attributes
   }
 }
+
+int RGWCreateBucket_OS_Lib::get_params()
+{
+  RGWAccessControlPolicy_S3 s3policy(s->cct);
+  policy = s3policy;
+
+  /* we don't have (any) headers, so just create canned ACLs */
+  return s3policy.create_canned(s->owner, s->bucket_owner, s->canned_acl);
+}
+
+void RGWCreateBucket_OS_Lib::send_response()
+{
+  /* TODO: something (maybe) */
+}
index 959aef058d609df39974a8cdb5410354c976acc6..d56c97aa7ed89ae4991831b288d7c627e85a223e 100644 (file)
@@ -49,6 +49,20 @@ public:
 
   virtual void send_response();
 
-}; /* RGWListBucket_OS_Lib */
+}; /* RGWStatBucket_OS_Lib */
+
+class RGWCreateBucket_OS_Lib : public RGWCreateBucket {
+public:
+  RGWCreateBucket_OS_Lib() {}
+  ~RGWCreateBucket_OS_Lib() {}
+  virtual int get_params();
+  virtual void send_response();
+}; /* RGWCreateBucket_OS_Lib */
+
+class RGWDeleteBucket_OS_Lib : public RGWDeleteBucket {
+public:
+  RGWDeleteBucket_OS_Lib() {}
+  ~RGWDeleteBucket_OS_Lib() {}
+}; /* RGWCreateBucket_OS_Lib */
 
 #endif /* RGW_OS_LIB_H */
index 9d3d2aed1345073279084721f1a391246cfb0d37..fe09d0b58ff1b6427ba3d58dc611140c449365c1 100644 (file)
@@ -55,6 +55,12 @@ TEST(LibRGW, MOUNT) {
   ASSERT_NE(fs, nullptr);
 }
 
+TEST(LibRGW, CREATE_BUCKET) {
+  struct stat st;
+  struct rgw_file_handle fh;
+  int ret = rgw_mkdir(fs, &fs->root_fh, "sorry_dave", 755, &st, &fh);
+}
+
 extern "C" {
   static bool r1_cb(const char* name, void *arg, uint64_t offset) {
     // don't need arg--it would point to fids1