Skip to content

Commit

Permalink
rgw_file: fix/update rgw_open flag arguments
Browse files Browse the repository at this point in the history
Allow passing POSIX open flags as well as api call flags.  Needed
for NFS3 support.

Signed-off-by: Matt Benjamin <[email protected]>
  • Loading branch information
mattbenjamin committed Aug 12, 2016
1 parent ca33241 commit ada29f7
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/include/rados/rgw_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,10 @@ int rgw_truncate(struct rgw_fs *rgw_fs,
*/
#define RGW_OPEN_FLAG_NONE 0x0000
#define RGW_OPEN_FLAG_CREATE 0x0001
#define RGW_OPEN_FLAG_V3 0x0002 /* ops have v3 semantics */

int rgw_open(struct rgw_fs *rgw_fs, struct rgw_file_handle *parent_fh,
uint32_t flags);
uint32_t posix_flags, uint32_t flags);

/*
close file
Expand Down
6 changes: 2 additions & 4 deletions src/rgw/rgw_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1319,7 +1319,7 @@ int rgw_truncate(struct rgw_fs *rgw_fs,
open file
*/
int rgw_open(struct rgw_fs *rgw_fs,
struct rgw_file_handle *fh, uint32_t flags)
struct rgw_file_handle *fh, uint32_t posix_flags, uint32_t flags)
{
RGWFileHandle* rgw_fh = get_rgwfh(fh);

Expand All @@ -1334,9 +1334,7 @@ int rgw_open(struct rgw_fs *rgw_fs,
if (! rgw_fh->is_file())
return -EISDIR;

// convert flags
uint32_t oflags = 0;
return rgw_fh->open(oflags);
return rgw_fh->open(flags);
}

/*
Expand Down
4 changes: 4 additions & 0 deletions src/rgw/rgw_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ namespace rgw {
static constexpr uint32_t FLAG_DELETED = 0x0080;
static constexpr uint32_t FLAG_UNLINK_THIS = 0x0100;
static constexpr uint32_t FLAG_LOCKED = 0x0200;
static constexpr uint32_t FLAG_STATELESS_OPEN = 0x0400;

#define CREATE_FLAGS(x) \
((x) & ~(RGWFileHandle::FLAG_CREATE|RGWFileHandle::FLAG_LOCK))
Expand Down Expand Up @@ -501,6 +502,9 @@ namespace rgw {
uint32_t open(uint32_t gsh_flags) {
lock_guard guard(mtx);
if (! (flags & FLAG_OPEN)) {
if (gsh_flags & RGW_OPEN_FLAG_V3) {
flags |= FLAG_STATELESS_OPEN;
}
flags |= FLAG_OPEN;
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/librgw_file_aw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ TEST(LibRGW, LOOKUP_OBJECT) {
}

TEST(LibRGW, OPEN1) {
int ret = rgw_open(fs, object_fh, RGW_OPEN_FLAG_NONE);
int ret = rgw_open(fs, object_fh, 0 /* posix flags */, RGW_OPEN_FLAG_NONE);
ASSERT_EQ(ret, 0);
}

Expand All @@ -234,7 +234,7 @@ TEST(LibRGW, CLOSE1) {
}

TEST(LibRGW, OPEN2) {
int ret = rgw_open(fs, object_fh, RGW_OPEN_FLAG_NONE);
int ret = rgw_open(fs, object_fh, 0 /* posix flags */, RGW_OPEN_FLAG_NONE);
ASSERT_EQ(ret, 0);
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/librgw_file_gp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ TEST(LibRGW, LOOKUP_OBJECT) {

TEST(LibRGW, OBJ_OPEN) {
if (do_get || do_put || do_readv || do_writev) {
int ret = rgw_open(fs, object_fh, 0 /* flags */);
int ret = rgw_open(fs, object_fh, 0 /* posix flags */, 0 /* flags */);
ASSERT_EQ(ret, 0);
object_open = true;
}
Expand Down
8 changes: 4 additions & 4 deletions src/test/librgw_file_nfsns.cc
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ TEST(LibRGW, SETUP_DIRS1) {
sf.rgw_fh->create_stat(&st, create_mask);

/* open handle */
rc = rgw_open(fs, sf.fh, 0 /* flags */);
rc = rgw_open(fs, sf.fh, 0 /* posix flags */, 0 /* flags */);
ASSERT_EQ(rc, 0);
ASSERT_TRUE(sf.rgw_fh->is_open());
/* stage seq write */
Expand Down Expand Up @@ -425,7 +425,7 @@ TEST(LibRGW, SETATTR) {
sf.rgw_fh->create_stat(&st, create_mask);

/* open handle */
rc = rgw_open(fs, sf.fh, 0 /* flags */);
rc = rgw_open(fs, sf.fh, 0 /* posix flags */, 0 /* flags */);
ASSERT_EQ(rc, 0);
ASSERT_TRUE(sf.rgw_fh->is_open());
/* stage seq write */
Expand Down Expand Up @@ -782,7 +782,7 @@ TEST(LibRGW, WRITEF_DIRS1) {
fobj.sync();

/* begin write transaction */
rc = rgw_open(fs, fobj.fh, 0 /* flags */);
rc = rgw_open(fs, fobj.fh, 0 /* posix flags */, 0 /* flags */);
ASSERT_EQ(rc, 0);
ASSERT_TRUE(fobj.rgw_fh->is_open());

Expand Down Expand Up @@ -987,7 +987,7 @@ TEST(LibRGW, MARKER1_SETUP_OBJECTS)
ASSERT_EQ(ret, 0);
obj.rgw_fh = get_rgwfh(obj.fh);
// open object--open transaction
ret = rgw_open(fs, obj.fh, RGW_OPEN_FLAG_NONE);
ret = rgw_open(fs, obj.fh, 0 /* posix flags */, RGW_OPEN_FLAG_NONE);
ASSERT_EQ(ret, 0);
ASSERT_TRUE(obj.rgw_fh->is_open());
// unstable write data
Expand Down

0 comments on commit ada29f7

Please sign in to comment.