From patchwork Fri Jun 3 07:39:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 629644 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rLbgT46yFz9t5C for ; Fri, 3 Jun 2016 17:43:33 +1000 (AEST) Received: from localhost ([::1]:52967 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8jlT-0006PX-Id for incoming@patchwork.ozlabs.org; Fri, 03 Jun 2016 03:43:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38312) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8jhP-0002mZ-1b for qemu-devel@nongnu.org; Fri, 03 Jun 2016 03:39:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8jhJ-0000aO-WF for qemu-devel@nongnu.org; Fri, 03 Jun 2016 03:39:18 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:38906) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8jhJ-0000aK-NM for qemu-devel@nongnu.org; Fri, 03 Jun 2016 03:39:13 -0400 Received: from pps.filterd (m0082756.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u537cgpg004820 for ; Fri, 3 Jun 2016 03:39:12 -0400 Message-Id: <201606030739.u537cgpg004820@mx0a-001b2d01.pphosted.com> Received: from e06smtp13.uk.ibm.com (e06smtp13.uk.ibm.com [195.75.94.109]) by mx0a-001b2d01.pphosted.com with ESMTP id 23b4m82sgb-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 03 Jun 2016 03:39:12 -0400 Received: from localhost by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 3 Jun 2016 08:39:10 +0100 Received: from d06dlp02.portsmouth.uk.ibm.com (9.149.20.14) by e06smtp13.uk.ibm.com (192.168.101.143) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 3 Jun 2016 08:39:07 +0100 X-IBM-Helo: d06dlp02.portsmouth.uk.ibm.com X-IBM-MailFrom: gkurz@linux.vnet.ibm.com X-IBM-RcptTo: qemu-devel@nongnu.org Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id 29D632190056 for ; Fri, 3 Jun 2016 08:38:40 +0100 (BST) Received: from d06av11.portsmouth.uk.ibm.com (d06av11.portsmouth.uk.ibm.com [9.149.37.252]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u537d7Y04522458 for ; Fri, 3 Jun 2016 07:39:07 GMT Received: from d06av11.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av11.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u537d6vg019083 for ; Fri, 3 Jun 2016 01:39:07 -0600 Received: from smtp.lab.toulouse-stg.fr.ibm.com (srv01.lab.toulouse-stg.fr.ibm.com [9.101.4.1]) by d06av11.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u537d6pW019077; Fri, 3 Jun 2016 01:39:06 -0600 Received: from bahia.huguette.org (icon-9-167-244-222.megacenter.de.ibm.com [9.167.244.222]) by smtp.lab.toulouse-stg.fr.ibm.com (Postfix) with ESMTP id 272FA220518; Fri, 3 Jun 2016 09:39:06 +0200 (CEST) From: Greg Kurz To: Greg Kurz Date: Fri, 03 Jun 2016 09:39:05 +0200 In-Reply-To: <146493859974.10856.12706484667247984078.stgit@bahia.huguette.org> References: <146493859974.10856.12706484667247984078.stgit@bahia.huguette.org> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16060307-0012-0000-0000-0000041862AF X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16060307-0013-0000-0000-0000142B36E3 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-06-03_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=62 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1606030086 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PATCH v2 2/4] 9p: introduce the V9fsDir type X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Aneesh Kumar K.V" , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" If we are to switch back to readdir(), we need a more complex type than DIR * to be able to serialize concurrent accesses to the directory stream. This patch introduces a placeholder type and fixes all users. Reviewed-by: Eric Blake Signed-off-by: Greg Kurz --- v2: added Eric's r-b --- hw/9pfs/9p-handle.c | 18 +++++++++--------- hw/9pfs/9p-local.c | 18 +++++++++--------- hw/9pfs/9p-proxy.c | 20 ++++++++++---------- hw/9pfs/9p.c | 12 ++++++------ hw/9pfs/9p.h | 6 +++++- 5 files changed, 39 insertions(+), 35 deletions(-) diff --git a/hw/9pfs/9p-handle.c b/hw/9pfs/9p-handle.c index 894041488abb..c5df05300700 100644 --- a/hw/9pfs/9p-handle.c +++ b/hw/9pfs/9p-handle.c @@ -112,7 +112,7 @@ static int handle_close(FsContext *ctx, V9fsFidOpenState *fs) static int handle_closedir(FsContext *ctx, V9fsFidOpenState *fs) { - return closedir(fs->dir); + return closedir(fs->dir.stream); } static int handle_open(FsContext *ctx, V9fsPath *fs_path, @@ -132,8 +132,8 @@ static int handle_opendir(FsContext *ctx, if (ret < 0) { return -1; } - fs->dir = fdopendir(ret); - if (!fs->dir) { + fs->dir.stream = fdopendir(ret); + if (!fs->dir.stream) { return -1; } return 0; @@ -141,24 +141,24 @@ static int handle_opendir(FsContext *ctx, static void handle_rewinddir(FsContext *ctx, V9fsFidOpenState *fs) { - rewinddir(fs->dir); + rewinddir(fs->dir.stream); } static off_t handle_telldir(FsContext *ctx, V9fsFidOpenState *fs) { - return telldir(fs->dir); + return telldir(fs->dir.stream); } static int handle_readdir_r(FsContext *ctx, V9fsFidOpenState *fs, struct dirent *entry, struct dirent **result) { - return readdir_r(fs->dir, entry, result); + return readdir_r(fs->dir.stream, entry, result); } static void handle_seekdir(FsContext *ctx, V9fsFidOpenState *fs, off_t off) { - seekdir(fs->dir, off); + seekdir(fs->dir.stream, off); } static ssize_t handle_preadv(FsContext *ctx, V9fsFidOpenState *fs, @@ -262,7 +262,7 @@ static int handle_fstat(FsContext *fs_ctx, int fid_type, int fd; if (fid_type == P9_FID_DIR) { - fd = dirfd(fs->dir); + fd = dirfd(fs->dir.stream); } else { fd = fs->fd; } @@ -409,7 +409,7 @@ static int handle_fsync(FsContext *ctx, int fid_type, int fd; if (fid_type == P9_FID_DIR) { - fd = dirfd(fs->dir); + fd = dirfd(fs->dir.stream); } else { fd = fs->fd; } diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c index 16f45f4854ca..3281acdef164 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -348,7 +348,7 @@ static int local_close(FsContext *ctx, V9fsFidOpenState *fs) static int local_closedir(FsContext *ctx, V9fsFidOpenState *fs) { - return closedir(fs->dir); + return closedir(fs->dir.stream); } static int local_open(FsContext *ctx, V9fsPath *fs_path, @@ -370,9 +370,9 @@ static int local_opendir(FsContext *ctx, char *path = fs_path->data; buffer = rpath(ctx, path); - fs->dir = opendir(buffer); + fs->dir.stream = opendir(buffer); g_free(buffer); - if (!fs->dir) { + if (!fs->dir.stream) { return -1; } return 0; @@ -380,12 +380,12 @@ static int local_opendir(FsContext *ctx, static void local_rewinddir(FsContext *ctx, V9fsFidOpenState *fs) { - rewinddir(fs->dir); + rewinddir(fs->dir.stream); } static off_t local_telldir(FsContext *ctx, V9fsFidOpenState *fs) { - return telldir(fs->dir); + return telldir(fs->dir.stream); } static int local_readdir_r(FsContext *ctx, V9fsFidOpenState *fs, @@ -395,7 +395,7 @@ static int local_readdir_r(FsContext *ctx, V9fsFidOpenState *fs, int ret; again: - ret = readdir_r(fs->dir, entry, result); + ret = readdir_r(fs->dir.stream, entry, result); if (ctx->export_flags & V9FS_SM_MAPPED) { entry->d_type = DT_UNKNOWN; } else if (ctx->export_flags & V9FS_SM_MAPPED_FILE) { @@ -411,7 +411,7 @@ again: static void local_seekdir(FsContext *ctx, V9fsFidOpenState *fs, off_t off) { - seekdir(fs->dir, off); + seekdir(fs->dir.stream, off); } static ssize_t local_preadv(FsContext *ctx, V9fsFidOpenState *fs, @@ -610,7 +610,7 @@ static int local_fstat(FsContext *fs_ctx, int fid_type, int err, fd; if (fid_type == P9_FID_DIR) { - fd = dirfd(fs->dir); + fd = dirfd(fs->dir.stream); } else { fd = fs->fd; } @@ -998,7 +998,7 @@ static int local_fsync(FsContext *ctx, int fid_type, int fd; if (fid_type == P9_FID_DIR) { - fd = dirfd(fs->dir); + fd = dirfd(fs->dir.stream); } else { fd = fs->fd; } diff --git a/hw/9pfs/9p-proxy.c b/hw/9pfs/9p-proxy.c index 00a4eb2a7bcf..63b074781589 100644 --- a/hw/9pfs/9p-proxy.c +++ b/hw/9pfs/9p-proxy.c @@ -633,7 +633,7 @@ static int proxy_close(FsContext *ctx, V9fsFidOpenState *fs) static int proxy_closedir(FsContext *ctx, V9fsFidOpenState *fs) { - return closedir(fs->dir); + return closedir(fs->dir.stream); } static int proxy_open(FsContext *ctx, V9fsPath *fs_path, @@ -652,14 +652,14 @@ static int proxy_opendir(FsContext *ctx, { int serrno, fd; - fs->dir = NULL; + fs->dir.stream = NULL; fd = v9fs_request(ctx->private, T_OPEN, NULL, "sd", fs_path, O_DIRECTORY); if (fd < 0) { errno = -fd; return -1; } - fs->dir = fdopendir(fd); - if (!fs->dir) { + fs->dir.stream = fdopendir(fd); + if (!fs->dir.stream) { serrno = errno; close(fd); errno = serrno; @@ -670,24 +670,24 @@ static int proxy_opendir(FsContext *ctx, static void proxy_rewinddir(FsContext *ctx, V9fsFidOpenState *fs) { - rewinddir(fs->dir); + rewinddir(fs->dir.stream); } static off_t proxy_telldir(FsContext *ctx, V9fsFidOpenState *fs) { - return telldir(fs->dir); + return telldir(fs->dir.stream); } static int proxy_readdir_r(FsContext *ctx, V9fsFidOpenState *fs, struct dirent *entry, struct dirent **result) { - return readdir_r(fs->dir, entry, result); + return readdir_r(fs->dir.stream, entry, result); } static void proxy_seekdir(FsContext *ctx, V9fsFidOpenState *fs, off_t off) { - seekdir(fs->dir, off); + seekdir(fs->dir.stream, off); } static ssize_t proxy_preadv(FsContext *ctx, V9fsFidOpenState *fs, @@ -791,7 +791,7 @@ static int proxy_fstat(FsContext *fs_ctx, int fid_type, int fd; if (fid_type == P9_FID_DIR) { - fd = dirfd(fs->dir); + fd = dirfd(fs->dir.stream); } else { fd = fs->fd; } @@ -936,7 +936,7 @@ static int proxy_fsync(FsContext *ctx, int fid_type, int fd; if (fid_type == P9_FID_DIR) { - fd = dirfd(fs->dir); + fd = dirfd(fs->dir.stream); } else { fd = fs->fd; } diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 12bd688f37d3..451ecbde0b08 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -231,7 +231,7 @@ static int v9fs_reopen_fid(V9fsPDU *pdu, V9fsFidState *f) } while (err == -EINTR && !pdu->cancelled); } } else if (f->fid_type == P9_FID_DIR) { - if (f->fs.dir == NULL) { + if (f->fs.dir.stream == NULL) { do { err = v9fs_co_opendir(pdu, f); } while (err == -EINTR && !pdu->cancelled); @@ -345,7 +345,7 @@ static int free_fid(V9fsPDU *pdu, V9fsFidState *fidp) retval = v9fs_co_close(pdu, &fidp->fs); } } else if (fidp->fid_type == P9_FID_DIR) { - if (fidp->fs.dir != NULL) { + if (fidp->fs.dir.stream != NULL) { retval = v9fs_co_closedir(pdu, &fidp->fs); } } else if (fidp->fid_type == P9_FID_XATTR) { @@ -443,7 +443,7 @@ void v9fs_reclaim_fd(V9fsPDU *pdu) reclaim_count++; } } else if (f->fid_type == P9_FID_DIR) { - if (f->fs.dir != NULL) { + if (f->fs.dir.stream != NULL) { /* * Up the reference count so that * a clunk request won't free this fid @@ -451,8 +451,8 @@ void v9fs_reclaim_fd(V9fsPDU *pdu) f->ref++; f->rclm_lst = reclaim_list; reclaim_list = f; - f->fs_reclaim.dir = f->fs.dir; - f->fs.dir = NULL; + f->fs_reclaim.dir.stream = f->fs.dir.stream; + f->fs.dir.stream = NULL; reclaim_count++; } } @@ -1887,7 +1887,7 @@ static void v9fs_readdir(void *opaque) retval = -EINVAL; goto out_nofid; } - if (!fidp->fs.dir) { + if (!fidp->fs.dir.stream) { retval = -EINVAL; goto out; } diff --git a/hw/9pfs/9p.h b/hw/9pfs/9p.h index 43378943cdda..92ee309ef4ba 100644 --- a/hw/9pfs/9p.h +++ b/hw/9pfs/9p.h @@ -167,13 +167,17 @@ typedef struct V9fsXattr int flags; } V9fsXattr; +typedef struct V9fsDir { + DIR *stream; +} V9fsDir; + /* * Filled by fs driver on open and other * calls. */ union V9fsFidOpenState { int fd; - DIR *dir; + V9fsDir dir; V9fsXattr xattr; /* * private pointer for fs drivers, that