Skip to content

Commit 74eee54

Browse files
guojidanidryomov
authored andcommitted
rbd: add the validate of the format and clone_format
[ idryomov: squash test_unsupported_clone_format() into test_clone_format() ] Fixes: https://tracker.ceph.com/issues/65744 Signed-off-by: junxiang Mu <1948535941@qq.com> Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
1 parent 3ee066e commit 74eee54

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

src/librbd/api/Image.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,8 +570,8 @@ int Image<I>::deep_copy(I *src, librados::IoCtx& dest_md_ctx,
570570
if (opts.get(RBD_IMAGE_OPTION_FORMAT, &format) != 0) {
571571
opts.set(RBD_IMAGE_OPTION_FORMAT, format);
572572
}
573-
if (format == 1) {
574-
lderr(cct) << "old format not supported for destination image" << dendl;
573+
if (format != 2) {
574+
lderr(cct) << "unsupported destination image format: " << format << dendl;
575575
return -EINVAL;
576576
}
577577
uint64_t stripe_unit = src->stripe_unit;

src/librbd/image/CloneRequest.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ void CloneRequest<I>::validate_options() {
8787

8888
uint64_t format = 0;
8989
m_opts.get(RBD_IMAGE_OPTION_FORMAT, &format);
90-
if (format < 2) {
91-
lderr(m_cct) << "format 2 or later required for clone" << dendl;
90+
if (format != 2) {
91+
lderr(m_cct) << "unsupported format for clone: " << format << dendl;
9292
complete(-EINVAL);
9393
return;
9494
}
@@ -124,6 +124,12 @@ void CloneRequest<I>::validate_options() {
124124
}
125125
}
126126

127+
if (m_clone_format < 1 || m_clone_format > 2) {
128+
lderr(m_cct) << "unsupported clone format: " << m_clone_format << dendl;
129+
complete(-EINVAL);
130+
return;
131+
}
132+
127133
if (m_clone_format == 1 &&
128134
m_parent_io_ctx.get_namespace() != m_ioctx.get_namespace()) {
129135
ldout(m_cct, 1) << "clone v2 required for cross-namespace clones" << dendl;

src/librbd/internal.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,11 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) {
638638
uint64_t format;
639639
if (opts.get(RBD_IMAGE_OPTION_FORMAT, &format) != 0)
640640
format = cct->_conf.get_val<uint64_t>("rbd_default_format");
641+
642+
if (format < 1 || format > 2) {
643+
lderr(cct) << "unsupported format: " << format << dendl;
644+
return -EINVAL;
645+
}
641646
bool old_format = format == 1;
642647

643648
// make sure it doesn't already exist, in either format

src/test/pybind/test_rbd.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,6 +1730,11 @@ def test_stripe_unit_and_count(self):
17301730

17311731
def test_clone_format(self):
17321732
clone_name2 = get_temp_image_name()
1733+
assert_raises(InvalidArgument, self.rbd.clone, ioctx, image_name,
1734+
'snap1', ioctx, clone_name2, features, clone_format=0)
1735+
assert_raises(InvalidArgument, self.rbd.clone, ioctx, image_name,
1736+
'snap1', ioctx, clone_name2, features, clone_format=3)
1737+
17331738
self.rbd.clone(ioctx, image_name, 'snap1', ioctx, clone_name2,
17341739
features, clone_format=1)
17351740
with Image(ioctx, clone_name2) as clone2:

0 commit comments

Comments
 (0)