From patchwork Fri Oct 10 05:57:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 5063731 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 3910DC11AC for ; Fri, 10 Oct 2014 06:01:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 524AF20253 for ; Fri, 10 Oct 2014 06:01:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 387952024F for ; Fri, 10 Oct 2014 06:01:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751819AbaJJGBE (ORCPT ); Fri, 10 Oct 2014 02:01:04 -0400 Received: from linux-libre.fsfla.org ([208.118.235.54]:50105 "EHLO linux-libre.fsfla.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751121AbaJJGBB (ORCPT ); Fri, 10 Oct 2014 02:01:01 -0400 Received: from freie.home (home.lxoliva.fsfla.org [172.31.160.22]) by linux-libre.fsfla.org (8.14.4/8.14.4/Debian-2ubuntu2.1) with ESMTP id s9A60pBN002643 for ; Fri, 10 Oct 2014 06:00:52 GMT Received: from free.home (free.home [172.31.160.1]) by freie.home (8.14.8/8.14.8) with ESMTP id s9A5vJId006032; Fri, 10 Oct 2014 02:57:22 -0300 From: Alexandre Oliva To: ceph-devel@vger.kernel.org Subject: rados.py: add tmap_to_omap method Organization: Free thinker, not speaking for the GNU Project Date: Fri, 10 Oct 2014 02:57:15 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) MIME-Version: 1.0 Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_TVD_MIME_EPI, T_TVD_MIME_NO_HEADERS, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP I wanted to script a tmap_to_omap conversion of a few million dirs, but running the rados program for each inode would have made it take too long, so I wrote the attached python script, that I'm now running in multiple copies in parallel with GNU parallel. Before it would run, however, I found out python bindings of rados's tmap_to_omap hadn't been implemented. It might have been because it takes a bool argument, and I couldn't find out how to pass it as such. I ended up forcing the bool argument to False and passing it as an int 0. This could fail on machines whose ABIs pass bools differently from ints, but IIRC bools are just aliases to char in C, at least within GCC, and since char is promoted to int for argument passing, passing an int should work, especially if it's zero. For nonzero values, endianness could matter if the argument is passed on the stack, so I settled for forcing it to zero. If anyone knows better, please let me know. --- Add tmap_to_omap method to rados python bindings, without the bool argument: it is forced to false. Signed-off-by: Alexandre Oliva --- src/pybind/rados.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/pybind/rados.py b/src/pybind/rados.py index 93e5040..a2394aa 100644 --- a/src/pybind/rados.py +++ b/src/pybind/rados.py @@ -1438,6 +1438,24 @@ returned %d, but should return zero on success." % (self.name, ret)) raise make_ex(ret, "Failed to stat %r" % key) return psize.value, time.localtime(pmtime.value) + def tmap_to_omap(self, key): + """ + Convert a dir from tmap to omap. + + :param key: the name of the object to convert + :type key: str + + :raises: :class:`TypeError` + :raises: :class:`Error` + :returns: int - 0 on success, otherwise raises an error + """ + self.require_ioctx_open() + ret = run_in_thread(self.librados.rados_tmap_to_omap, + (self.io, c_char_p(key), c_int(0))) + if ret < 0: + raise make_ex(ret, "Failed to convert %s from tmap to omap" % key) + return 0 + def get_xattr(self, key, xattr_name): """ Get the value of an extended attribute on an object.