From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:55559) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QwbTm-0001oL-Dm for qemu-devel@nongnu.org; Thu, 25 Aug 2011 11:04:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QwbTb-0001xv-9o for qemu-devel@nongnu.org; Thu, 25 Aug 2011 11:04:20 -0400 Received: from e23smtp03.au.ibm.com ([202.81.31.145]:37225) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QwbTa-0001xJ-Pk for qemu-devel@nongnu.org; Thu, 25 Aug 2011 11:04:15 -0400 Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [202.81.31.247]) by e23smtp03.au.ibm.com (8.14.4/8.13.1) with ESMTP id p7PEwpWw028264 for ; Fri, 26 Aug 2011 00:58:51 +1000 Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay05.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p7PF2r4x1249360 for ; Fri, 26 Aug 2011 01:02:53 +1000 Received: from d23av02.au.ibm.com (loopback [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p7PF4DFS004613 for ; Fri, 26 Aug 2011 01:04:13 +1000 From: "Aneesh Kumar K.V" Date: Thu, 25 Aug 2011 20:33:43 +0530 Message-Id: <1314284624-14821-6-git-send-email-aneesh.kumar@linux.vnet.ibm.com> In-Reply-To: <1314284624-14821-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> References: <1314284624-14821-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 5/6] hw/9pfs: Add directory reclaim support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aliguori@us.ibm.com, "Aneesh Kumar K.V" Signed-off-by: Aneesh Kumar K.V --- hw/9pfs/codir.c | 9 +++++++++ hw/9pfs/virtio-9p.c | 31 +++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/hw/9pfs/codir.c b/hw/9pfs/codir.c index 86adc87..f17f927 100644 --- a/hw/9pfs/codir.c +++ b/hw/9pfs/codir.c @@ -97,6 +97,12 @@ int v9fs_co_opendir(V9fsState *s, V9fsFidState *fidp) err = 0; } }); + if (!err) { + total_open_fd++; + if (total_open_fd > open_fd_hw) { + v9fs_reclaim_fd(s); + } + } return err; } @@ -111,5 +117,8 @@ int v9fs_co_closedir(V9fsState *s, DIR *dir) err = -errno; } }); + if (!err) { + total_open_fd--; + } return err; } diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c index 6529216..16f7d4e 100644 --- a/hw/9pfs/virtio-9p.c +++ b/hw/9pfs/virtio-9p.c @@ -266,7 +266,17 @@ static V9fsFidState *get_fid(V9fsState *s, int32_t fid) return NULL; } } - } + } else if (f->fid_type == P9_FID_DIR) { + if (f->fs.dir == NULL) { + do { + err = v9fs_co_opendir(s, f); + } while (err == -EINTR); + if (err < 0) { + f->ref--; + return NULL; + } + } + } /* * Mark the fid as referenced so that the LRU * reclaim won't close the file descriptor @@ -348,7 +358,9 @@ static int free_fid(V9fsState *s, V9fsFidState *fidp) retval = v9fs_co_close(s, fidp->fs.fd); } } else if (fidp->fid_type == P9_FID_DIR) { - retval = v9fs_co_closedir(s, fidp->fs.dir); + if (fidp->fs.dir != NULL) { + retval = v9fs_co_closedir(s, fidp->fs.dir); + } } else if (fidp->fid_type == P9_FID_XATTR) { retval = v9fs_xattr_fid_clunk(s, fidp); } @@ -429,6 +441,19 @@ void v9fs_reclaim_fd(V9fsState *s) f->fs.fd = -1; reclaim_count++; } + } else if (f->fid_type == P9_FID_DIR) { + if (f->fs.dir != NULL) { + /* + * Up the reference count so that + * a clunk request won't free this fid + */ + f->ref++; + f->rclm_lst = reclaim_list; + reclaim_list = f; + f->fs_reclaim.dir = f->fs.dir; + f->fs.dir = NULL; + reclaim_count++; + } } if (reclaim_count >= open_fd_rc) { break; @@ -443,6 +468,8 @@ void v9fs_reclaim_fd(V9fsState *s) reclaim_list = f->rclm_lst; if (f->fid_type == P9_FID_FILE) { v9fs_co_close(s, f->fs_reclaim.fd); + } else if (f->fid_type == P9_FID_DIR) { + v9fs_co_closedir(s, f->fs_reclaim.dir); } f->rclm_lst = NULL; /* -- 1.7.4.1