Skip to content

Commit

Permalink
rbd.cc: add readonly option for "rbd map"
Browse files Browse the repository at this point in the history
The device could only be set to rw(default) when mapping
now. This patch only handle the user space, because the
kernel part has been completed.

Signed-off-by: Guangliang Zhao <[email protected]>
Reviewed-by: Josh Durgin <[email protected]>
  • Loading branch information
Guangliang Zhao authored and jdurgin committed Oct 1, 2013
1 parent 5671137 commit 409aba6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions doc/man/8/rbd.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ Parameters

Make json or xml formatted output more human-readable.

.. option:: --read-only

Set device readonly when mapping image.


Commands
========
Expand Down
5 changes: 5 additions & 0 deletions man/rbd.8
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ Specifies output formatting (default: plain, json, xml)
.B \-\-pretty\-format
Make json or xml formatted output more human\-readable.
.UNINDENT
.INDENT 0.0
.TP
.B \-\-read\-only
Set device readonly when mapping image.
.UNINDENT
.SH COMMANDS
.INDENT 0.0
.TP
Expand Down
11 changes: 10 additions & 1 deletion src/rbd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ static string dir_info_oid = RBD_INFO;
bool udevadm_settle = true;
bool progress = true;
bool resize_allow_shrink = false;
bool read_only = false;

#define dout_subsys ceph_subsys_rbd

Expand Down Expand Up @@ -151,6 +152,7 @@ void usage()
" --pretty-format make json or xml output more readable\n"
" --no-settle do not wait for udevadm to settle on map/unmap\n"
" --no-progress do not show progress for long-running commands\n"
" --read-only set device readonly when mapping image\n"
" --allow-shrink allow shrinking of an image when resizing\n";
}

Expand Down Expand Up @@ -1640,8 +1642,13 @@ static int do_kernel_add(const char *poolname, const char *imgname,
oss << ",";
}

if (read_only)
oss << " ro";
else
oss << " rw";

const char *user = g_conf->name.get_id().c_str();
oss << " name=" << user;
oss << ",name=" << user;

char key_name[strlen(user) + strlen("client.") + 1];
snprintf(key_name, sizeof(key_name), "client.%s", user);
Expand Down Expand Up @@ -2200,6 +2207,8 @@ int main(int argc, const char **argv)
lock_tag = strdup(val.c_str());
} else if (ceph_argparse_flag(args, i, "--no-settle", (char *)NULL)) {
udevadm_settle = false;
} else if (ceph_argparse_flag(args, i, "--read-only", (char *)NULL)) {
read_only = true;
} else if (ceph_argparse_flag(args, i, "--no-progress", (char *)NULL)) {
progress = false;
} else if (ceph_argparse_flag(args, i , "--allow-shrink", (char *)NULL)) {
Expand Down

0 comments on commit 409aba6

Please sign in to comment.