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

RadosClient: result code may overflow #6489

Merged
merged 2 commits into from Nov 20, 2015
Merged

Conversation

xiexingguo
Copy link
Member

For more details about this issue, check http://tracker.ceph.com/issues/13715

@tchaikov
Copy link
Contributor

tchaikov commented Nov 9, 2015

@xiexingguo i am not sure this is the right fix. probably we should deprecate these two methods and have new methods overloading them, for example:

int pool_requires_alignment(int64_t pool_id, bool *requires);

by returning the error code, and pass a pointer for the "[out]" parameter?

@liewegas and @dillaman what do you think?

@tchaikov
Copy link
Contributor

tchaikov commented Nov 9, 2015

and your Signed-off-by does not look right: missing angle brackets.

@liewegas
Copy link
Member

liewegas commented Nov 9, 2015

Agree on fixing the function prototypes to have a return code separate from the output arguments.

@dillaman
Copy link

dillaman commented Nov 9, 2015

@tchaikov I like the new function idea since it's safer. However, to preserve API compatibility, the new function would need to be named:

int pool_requires_alignment2(int64_t pool_id, bool *requires);

@xiexingguo xiexingguo force-pushed the xxg-wip-13715 branch 2 times, most recently from 3c06b09 to 031bee2 Compare November 10, 2015 12:46
@ghost
Copy link

ghost commented Nov 10, 2015

@xiexingguo please ignore the false negative from the bot

pool_requires_alignment and pool_required_alignment may produce overflowed results and need to refactered.
Fixes: ceph#13715
Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
objecter->put_osdmap_read();
return 0;
}

uint64_t librados::RadosClient::pool_required_alignment(int64_t pool_id)
{
int r = wait_for_osdmap();
Copy link
Contributor

Choose a reason for hiding this comment

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

@xiexingguo could you reimplement the deprecated methods using the new ones in another commit in this pr? so we don't less duplicated code and the logic reveals the problem of the old methods in a more visible way.

Copy link
Member Author

Choose a reason for hiding this comment

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

@tchaikov Sorry, I don't quite understand what do you mean. Can you make an example?

Copy link
Contributor

Choose a reason for hiding this comment

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

@xiexingguo

diff --git a/src/librados/RadosClient.cc b/src/librados/RadosClient.cc
index a01ae7d..6157e35 100644
--- a/src/librados/RadosClient.cc
+++ b/src/librados/RadosClient.cc
@@ -108,16 +108,13 @@ bool librados::RadosClient::pool_requires_alignment(int64_t pool_id)

 uint64_t librados::RadosClient::pool_required_alignment(int64_t pool_id)
 {
-  int r = wait_for_osdmap();
+  uint64_t alignment = 0;
+  int r = pool_required_alignment2(pool_id, &alignment);
   if (r < 0) {
     return r;
+  } else {
+    return alignment;
   }
-
-  const OSDMap *osdmap = objecter->get_osdmap_read();
-  uint64_t ret = osdmap->have_pg_pool(pool_id) ?
-    osdmap->get_pg_pool(pool_id)->required_alignment() : 0;
-  objecter->put_osdmap_read();
-  return ret;
 }

Copy link
Member Author

Choose a reason for hiding this comment

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

@tchaikov Got it. I will do it now.

@xiexingguo
Copy link
Member Author

@tchaikov UT passed, please review.

@tchaikov
Copy link
Contributor

lgtm.

@xiexingguo
Copy link
Member Author

@liewegas Hi, sage, could you please add this one for test too?

uint64_t alignment;
int r = pool_required_alignment2(pool_id, &alignment);
if (r < 0) {
return r;
Copy link
Contributor

Choose a reason for hiding this comment

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

One problem here. Return a negative int as uint64_t. What does caller do with a huge number? Should it return 0 and caller should check for that as an error indication?

Copy link
Contributor

Choose a reason for hiding this comment

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

I see that is why there is a new interface, but I think returning 0 on error for the original interface is reasonable.

@xiexingguo
Copy link
Member Author

@dzafman Fixup as you suggested. Please review.

@dzafman
Copy link
Contributor

dzafman commented Nov 12, 2015

lgtm

so we don't less duplicated code and the logic reveals the problem of the old methods in a more visible way.
Fixes: ceph#13715
Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
liewegas added a commit that referenced this pull request Nov 20, 2015
librados: fix pool alignment API overflow issue

Reviewed-by: Kefu Chai <kchai@redhat.com>
Reviewed-by: David Zafman <dzafman@redhat.com>
@liewegas liewegas merged commit b584388 into ceph:master Nov 20, 2015
@xiexingguo xiexingguo deleted the xxg-wip-13715 branch November 20, 2015 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants