From patchwork Thu May 19 20:22:32 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Chrisman X-Patchwork-Id: 799782 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p4JKNV8G018246 for ; Thu, 19 May 2011 20:23:31 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934664Ab1ESUXH (ORCPT ); Thu, 19 May 2011 16:23:07 -0400 Received: from mail-pv0-f174.google.com ([74.125.83.174]:36203 "EHLO mail-pv0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933926Ab1ESUW4 (ORCPT ); Thu, 19 May 2011 16:22:56 -0400 Received: by pvg12 with SMTP id 12so1349946pvg.19 for ; Thu, 19 May 2011 13:22:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=tUm9MtXi810WOD4uiXWfvbB9gIUMsBCom2LL9NVDQxg=; b=m6N68dRzqF05Y4LRDOrcTJf1LLvA0RmSS8PAHf29nm66GzPXmwm2obEIZjAfu0xh4W v6+hQBMLF99l1Kcl9LJtUCMDmrEkR6oekhh3iWuiaVCXPPkgxW96uVBRYwdRG5UHQBxS T0BPfTQUL6D4FVRcH+jvUkH1ShSSPRB8JQtto= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=m2+2th0UhYpNY0yHfawQ0WFCekkudxZU/AUJEVzoeZ5GEpsOGKUN8OLwY72F94TnzU nBqyrBj3QAfZZu7Mq25Nbp8ihx4MEOD/yXMo1rnfsnOeyipmfRV80ywQmTiCIY50zzY8 9sea8cmZAtGzel9dVHQ5xLRqDyOefdBcRXHw0= Received: by 10.142.156.12 with SMTP id d12mr2177374wfe.184.1305836575751; Thu, 19 May 2011 13:22:55 -0700 (PDT) Received: from localhost.localdomain (70-35-37-146.static.wiline.com [70.35.37.146]) by mx.google.com with ESMTPS id k7sm2584950wfa.14.2011.05.19.13.22.54 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 19 May 2011 13:22:54 -0700 (PDT) From: Brian Chrisman To: ceph-devel@vger.kernel.org Cc: Brian Chrisman Subject: [PATCH 1/2] add ceph_readdir() to libceph Date: Thu, 19 May 2011 13:22:32 -0700 Message-Id: <1305836553-393-2-git-send-email-brchrisman@gmail.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1305836553-393-1-git-send-email-brchrisman@gmail.com> References: <1305836553-393-1-git-send-email-brchrisman@gmail.com> Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Thu, 19 May 2011 20:23:31 +0000 (UTC) Signed-off-by: Brian Chrisman --- src/client/Client.cc | 35 +++++++++++++++++++++++++++++++++-- src/client/Client.h | 1 + src/include/ceph/libceph.h | 1 + src/libceph.cc | 5 +++++ 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index e4b400c..0284c03 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -4298,8 +4298,6 @@ int Client::readdir_r_cb(dir_result_t *d, add_dirent_cb_t cb, void *p) } - - int Client::readdir_r(dir_result_t *d, struct dirent *de) { return readdirplus_r(d, de, 0, 0); @@ -4337,6 +4335,39 @@ static int _readdir_single_dirent_cb(void *p, struct dirent *de, struct stat *st return 0; } +struct dirent * Client::readdir(dir_result_t *d) +{ + int ret; + static int stmask; + static struct dirent de; + static struct stat st; + single_readdir sr; + sr.de = &de; + sr.st = &st; + sr.stmask = &stmask; + sr.full = false; + + /* + * Return mechanisms are non-obvious (callback appears intended for multi-read mechanism like cfuse) + * readdir_r_cb=0 end of directory reached on prior call + * readdir_r_cb=0 entry filled and offset now at end of the directory + * readdir_r_cb=-1 entry is filled successfully, not end of dir + * readdir_r_cb=-(other) on error + * callback leaves sr.full=false when 'offset is at end of directory' + * callback may leave sr.full=false on error + * callback sets sr.full=true on 'successfully read dirent' + */ + ret = readdir_r_cb(d, _readdir_single_dirent_cb, (void *)&sr); + if (ret < -1) { + errno = -ret; + return (dirent *) NULL; + } + if (sr.full) { + return &de; + } + return (dirent *) NULL; +} + int Client::readdirplus_r(dir_result_t *d, struct dirent *de, struct stat *st, int *stmask) { single_readdir sr; diff --git a/src/client/Client.h b/src/client/Client.h index b36621d..e10979d 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -1204,6 +1204,7 @@ public: int readdir_r_cb(dir_result_t *dirp, add_dirent_cb_t cb, void *p); + struct dirent * readdir(dir_result_t *d); int readdir_r(dir_result_t *dirp, struct dirent *de); int readdirplus_r(dir_result_t *dirp, struct dirent *de, struct stat *st, int *stmask); diff --git a/src/include/ceph/libceph.h b/src/include/ceph/libceph.h index f9fc29e..bf28402 100644 --- a/src/include/ceph/libceph.h +++ b/src/include/ceph/libceph.h @@ -76,6 +76,7 @@ int ceph_chdir(struct ceph_mount_info *cmount, const char *s); int ceph_opendir(struct ceph_mount_info *cmount, const char *name, struct ceph_dir_result **dirpp); int ceph_closedir(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp); +struct dirent * ceph_readdir(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp); int ceph_readdir_r(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp, struct dirent *de); int ceph_readdirplus_r(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp, struct dirent *de, struct stat *st, int *stmask); diff --git a/src/libceph.cc b/src/libceph.cc index 6388bde..54993ac 100644 --- a/src/libceph.cc +++ b/src/libceph.cc @@ -319,6 +319,11 @@ extern "C" int ceph_closedir(struct ceph_mount_info *cmount, struct ceph_dir_res return cmount->get_client()->closedir((dir_result_t*)dirp); } +extern "C" struct dirent * ceph_readdir(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp) +{ + return cmount->get_client()->readdir((dir_result_t*)dirp); +} + extern "C" int ceph_readdir_r(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp, struct dirent *de) { return cmount->get_client()->readdir_r((dir_result_t*)dirp, de);