From: Christian Brunner <chb@muc.de>
To: ceph-devel@vger.kernel.org
Subject: [PATCH 1/2 v2] rbd: allow importing from stdin
Date: Wed, 16 May 2012 22:32:33 +0200 [thread overview]
Message-ID: <20120516203233.GA32219@sir.fritz.box> (raw)
This patch allows importing images from stdin with the following command:
rbd import --size=<size in MB> - [dest-image]
v1 -> v2: stat stdin as well
Signed-off-by: Christian Brunner <chb@muc.de>
---
src/rbd.cc | 26 +++++++++++++++++++-------
1 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/src/rbd.cc b/src/rbd.cc
index 655d9a2..1a0c510 100644
--- a/src/rbd.cc
+++ b/src/rbd.cc
@@ -402,16 +402,21 @@ done_img:
}
static int do_import(librbd::RBD &rbd, librados::IoCtx& io_ctx,
- const char *imgname, int *order, const char *path)
+ const char *imgname, int *order, const char *path,
+ int64_t size)
{
- int fd = open(path, O_RDONLY);
- int r;
- int64_t size = 0;
+ int fd, r;
struct stat stat_buf;
string md_oid;
struct fiemap *fiemap;
MyProgressContext pc("Importing image");
+ if (! strcmp(path, "-")) {
+ fd = 0;
+ } else {
+ fd = open(path, O_RDONLY);
+ }
+
if (fd < 0) {
r = -errno;
cerr << "error opening " << path << std::endl;
@@ -424,7 +429,9 @@ static int do_import(librbd::RBD &rbd, librados::IoCtx& io_ctx,
cerr << "stat error " << path << std::endl;
return r;
}
- size = (uint64_t)stat_buf.st_size;
+ if (stat_buf.st_size)
+ size = (uint64_t)stat_buf.st_size;
+
if (!size) {
r = get_block_device_size(fd, &size);
if (r < 0) {
@@ -505,7 +512,12 @@ static int do_import(librbd::RBD &rbd, librados::IoCtx& io_ctx,
while (cur_seg) {
bufferptr p(cur_seg);
//cerr << "reading " << cur_seg << " bytes at offset " << file_pos << std::endl;
- ssize_t rval = TEMP_FAILURE_RETRY(::pread(fd, p.c_str(), cur_seg, file_pos));
+ ssize_t rval;
+ if(extent == 0 && fiemap->fm_extents[extent].fe_logical == 0) {
+ rval = TEMP_FAILURE_RETRY(::read(fd, p.c_str(), cur_seg));
+ } else {
+ rval = TEMP_FAILURE_RETRY(::pread(fd, p.c_str(), cur_seg, file_pos));
+ }
if (rval < 0) {
r = -errno;
cerr << "error reading file: " << cpp_strerror(r) << std::endl;
@@ -1303,7 +1315,7 @@ int main(int argc, const char **argv)
cerr << "pathname should be specified" << std::endl;
exit(1);
}
- r = do_import(rbd, dest_io_ctx, destname, &order, path);
+ r = do_import(rbd, dest_io_ctx, destname, &order, path, size);
if (r < 0) {
cerr << "import failed: " << cpp_strerror(-r) << std::endl;
exit(1);
--
1.7.1
next reply other threads:[~2012-05-16 20:34 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-16 20:32 Christian Brunner [this message]
2012-05-16 22:25 ` [PATCH 1/2 v2] rbd: allow importing from stdin Yehuda Sadeh Weinraub
2012-05-16 23:51 ` Tommi Virtanen
2012-05-16 23:58 ` Josh Durgin
2012-05-17 0:00 ` Tommi Virtanen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120516203233.GA32219@sir.fritz.box \
--to=chb@muc.de \
--cc=ceph-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.