Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rbd: introduce v2 format for rbd export/import. #10487

Merged
merged 25 commits into from Feb 19, 2017

Conversation

yangdongsheng
Copy link
Contributor

@yangdongsheng
Copy link
Contributor Author

@dillaman
This PR added this feature http://tracker.ceph.com/issues/13186 , please help to take a look. thanx.

@yangdongsheng
Copy link
Contributor Author

@dillaman I found there is still some bug in this PR, so it's not ready for code-review.

@yangdongsheng yangdongsheng changed the title rbd: add --with-snaps to allow user to import or export snapshots at the same time with image [RFC] rbd: add --with-snaps to allow user to import or export snapshots at the same time with image Jul 29, 2016
@yangdongsheng yangdongsheng changed the title [RFC] rbd: add --with-snaps to allow user to import or export snapshots at the same time with image rbd: add --with-snaps to allow user to import or export snapshots at the same time with image Aug 1, 2016
@yangdongsheng
Copy link
Contributor Author

@dillaman it passed my local manual testing now, please help to take a look. thanx

@yangdongsheng yangdongsheng force-pushed the rbd_export branch 3 times, most recently from e16ab22 to 7125613 Compare August 3, 2016 01:26
@@ -196,7 +196,7 @@ static int do_merge_diff(const char *first, const char *second,
}
}

//We just handle the case like 'banner, [ftag], [ttag], stag, [wztag]*,etag',
//We just handle the case like 'banner, [ftag], [ttag], [stag], [wztag]*, [etag]',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was an attempt to say that the "s" and "e" tags are not optional and the ones in the brackets are optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right. 👍

@dillaman
Copy link

dillaman commented Aug 5, 2016

@yangdongsheng I'd recommend combining Export/ExportDiff and Import/ImportDiff into the same file now that they are going to be interdependent.

@dillaman
Copy link

dillaman commented Aug 5, 2016

@yangdongsheng It might be cleaner to just 100% re-use the existing export/import diff format for the export/import with snaps. Just create a new "v2" header to distinguish the new behavior that it might contain >1 snapshot segment. Then on import(diff), if it's a v2, it should keep looping when it gets to the end snapshot marker, then the next field should be a from snapshot marker, data, etc, end snapshot, etc.

goto done;
}
// seek back to the beginning.
lseek(fd, 0, SEEK_SET);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't you just set "import_snaps" to false here and eliminate the need for new_format?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I am not sure what's your suggestion here, but I can explain the logic here more clear.

(1).import_snaps == true means --with-snaps is specified.
(2).(from_stdin == false )means importing something from file.

Then there are 3 possibility we will into this if statement.
(1). (import_snaps == true) and (from_stdin == true), in this case, when we found it's old format, because it's from stdin, we can't seek back, so return -EINVAL. That means, you have to make sure the you are accepting a new format importing stdin when you specify --with-snaps manually.

(2). (import_snaps == true) and (from_stdin == false), in this case, when we found it's a old format. we will lseek to the beginning, because it's from a fd. and the all data in file should be imported into image.

(3). (import_snaps == false) and (from_stdin == false), in this case, --with-snaps are not specified, and we are importing data from a file. then we try to check the banner at first, if we found it's old format. lseek to 0 to import it in old manner.

In this way, we can keep the backforwad compatability for the old format of export/exportdiff

@yangdongsheng
Copy link
Contributor Author

Hi @dillaman sorry for the late update. Please help to take a look again. thanx

@yangdongsheng
Copy link
Contributor Author

@dillaman do you have a time to take a look at this PR?

rbd info testimg_import
rbd info testimg_import@snap
rm ${TMPDIR}/img
rbd snap rm testimg_import@snap

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compare the contents between snaps and image HEAD

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okey

@@ -711,8 +711,11 @@ void ExclusiveLock<I>::handle_shutdown(int r) {

m_image_ctx.aio_work_queue->clear_require_lock_on_read();
m_image_ctx.aio_work_queue->unblock_writes();
m_image_ctx.image_watcher->flush(util::create_context_callback<
ExclusiveLock<I>, &ExclusiveLock<I>::complete_shutdown>(this));
if (m_image_ctx.image_watcher == nullptr)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to make any changes here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got a segmentation fault without this change in "rbd export --with-snaps"

@@ -154,6 +213,8 @@ void get_arguments(po::options_description *positional,
at::add_path_options(positional, options,
"export file (or '-' for stdout)");
at::add_no_progress_option(options);
options->add_options()
("with-snaps", po::bool_switch(), "export snapshots at the same time");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: for some reason, "with-snaps" doesn't feel clear to me. Perhaps "--export-snapshots" or "--include-snapshots"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okey

@@ -857,5 +857,265 @@ std::string timestr(time_t t) {
return buf;
}

int export_diff_fd(librbd::Image& image, const char *fromsnapname,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: I would recommend combining Export.cc and ExportDiff.cc into the same file and then keeping the export_diff and export_diff_fd within the new combined Export.cc file. Same logic for Import.cc and ImportDiff.cc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okey.

#include <string>
#include <boost/program_options.hpp>

namespace rbd {
namespace utils {

static const std::string RBD_IMAGE_BANNER ("rbd image v1\n");
static const std::string RBD_IMAGE_SNAPS_BANNER ("rbd image snaps v1\n");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: I can foresee wanted to eventually export other image attributes in addition to snapshots (e.g. features, metadata, etc). Therefore, perhaps it should be a v2 banner and then the export format should have a set of flag at the start that indicate what optional attributes have been included in the export (e.g. snapshots, features, etc).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed

if (with_snaps) {
// header
bufferlist bl;
bl.append(utils::RBD_IMAGE_BANNER);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: new RBD_IMAGE_BANNER_V2

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okey

}

if (r < 0) {
if (with_snaps) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you would first want to export the image starting at the first available snapshot via export_diff (i.e. only record the data that actually exists in the image), then iterating through all the available snapshots to generate diffs for each successive snapshot until you get to the specified head location. This would create a nice sparse export.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then we can't import a image without snaps in this case.

rbd export --with-snaps test test.export
rbd import test.import test.export

I mean, sometimes, we can get a exported image with snapshots, but we only want to import a full image from it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I name it as "with snaps" rather than "snaps mode". But yes, --include-snapshots sounds better. :)

if (from_stdin && (image_pos + (size_t)blklen) > size) {
size *= 2;
r = image.resize(size);
lseek(fd, size, SEEK_CUR);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like exported image has the full (non-sparse) image export which isn't used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this will be used when we import a image without --with-snaps. Sometimes, maybe we only want to import a full image even the snaps were exported already.

@dillaman
Copy link

@yangdongsheng Sorry -- the comments were sitting in "pending" state for days since I forgot to publish them.

Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
…xport.sh

Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
… importing test cases.

Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
…port

Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
…platform

Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
…ff and import.

Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
@dillaman dillaman merged commit b2b1899 into ceph:master Feb 19, 2017
@tchaikov
Copy link
Contributor

tchaikov commented Mar 30, 2017

@yangdongsheng and @dillaman

the workunit change breaks the jewel-x-singleton test, see http://pulpito.ceph.com/kchai-2017-03-30_14:32:23-rados-wip-13999-kefu---basic-mira/966061/

2017-03-30T14:41:21.411 INFO:tasks.workunit.client.0.mira071.stderr:+ rbd export --export-format 2 testimg /tmp/rbd_import_export_13580/img_v2
2017-03-30T14:41:21.434 INFO:tasks.workunit.client.0.mira071.stderr:rbd: unrecognised option '--export-format'

@dillaman
Copy link

@tchaikov Please open a tracker ticket -- this PR is already merged

@tchaikov
Copy link
Contributor

@dillaman sure, will do tomorrow. just wanted to give you guys a quick heads-up in case you run into this.

@dillaman
Copy link

dillaman commented Mar 30, 2017

@tchaikov It's a teuthology issue where the test case specifies that the "jewel" branch of the workunit should be used, but instead it downloads the "head" version (d463f52) of the workunit. Can't help but notice that particular commit changes the behavior of tasks/workunit.py so potentially this issue was just introduced?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants