From patchwork Thu Sep 15 14:24:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 9333909 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3FD2A607FD for ; Thu, 15 Sep 2016 14:56:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 33D18296B9 for ; Thu, 15 Sep 2016 14:56:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 27FCF298EB; Thu, 15 Sep 2016 14:56:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3922E296B9 for ; Thu, 15 Sep 2016 14:56:32 +0000 (UTC) Received: from localhost ([::1]:35293 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkY5X-00006U-BM for patchwork-qemu-devel@patchwork.kernel.org; Thu, 15 Sep 2016 10:56:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45907) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkXai-0007Oh-7t for qemu-devel@nongnu.org; Thu, 15 Sep 2016 10:24:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bkXac-0001zH-6n for qemu-devel@nongnu.org; Thu, 15 Sep 2016 10:24:39 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:33760 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkXab-0001z5-Vn for qemu-devel@nongnu.org; Thu, 15 Sep 2016 10:24:34 -0400 Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id u8FENxXZ040120 for ; Thu, 15 Sep 2016 10:24:33 -0400 Received: from e33.co.us.ibm.com (e33.co.us.ibm.com [32.97.110.151]) by mx0b-001b2d01.pphosted.com with ESMTP id 25fv624298-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 15 Sep 2016 10:24:33 -0400 Received: from localhost by e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 15 Sep 2016 08:24:32 -0600 Received: from d03dlp01.boulder.ibm.com (9.17.202.177) by e33.co.us.ibm.com (192.168.1.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 15 Sep 2016 08:24:31 -0600 X-IBM-Helo: d03dlp01.boulder.ibm.com X-IBM-MailFrom: groug@kaod.org Received: from b03cxnp07028.gho.boulder.ibm.com (b03cxnp07028.gho.boulder.ibm.com [9.17.130.15]) by d03dlp01.boulder.ibm.com (Postfix) with ESMTP id 5023B1FF001E; Thu, 15 Sep 2016 08:24:10 -0600 (MDT) Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u8FEO6BL12779816; Thu, 15 Sep 2016 07:24:28 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A3BFB78051; Thu, 15 Sep 2016 08:24:28 -0600 (MDT) Received: from [192.168.66.108] (unknown [9.164.164.67]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP id D719278056; Thu, 15 Sep 2016 08:24:27 -0600 (MDT) From: Greg Kurz To: qemu-devel@nongnu.org Date: Thu, 15 Sep 2016 16:24:26 +0200 In-Reply-To: <147394943723.684.13967719989878111420.stgit@bahia> References: <147394943723.684.13967719989878111420.stgit@bahia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16091514-0008-0000-0000-0000059049FE X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00005765; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000185; SDB=6.00757975; UDB=6.00359635; IPR=6.00531588; BA=6.00004731; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00012682; XFM=3.00000011; UTC=2016-09-15 14:24:32 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16091514-0009-0000-0000-00003B33BE58 Message-Id: <147394946678.684.4033631335977230764.stgit@bahia> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-09-15_08:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1609020000 definitions=main-1609150194 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH 4/4] 9pfs: introduce v9fs_path_sprintf() helper 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: Greg Kurz , "Aneesh Kumar K.V" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This helper is similar to v9fs_string_sprintf(), but it includes the terminating NUL character in the size field. This is to avoid doing v9fs_string_sprintf((V9fsString *) &path) and then bumping the size. Affected users are changed to use this new helper. Signed-off-by: Greg Kurz Reviewed-by: Cédric Le Goater --- hw/9pfs/9p-local.c | 7 ++----- hw/9pfs/9p-proxy.c | 7 ++----- hw/9pfs/9p.c | 19 ++++++++++++++++--- hw/9pfs/9p.h | 1 + 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c index 3f271fcbd2c5..845675e7a1bb 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -1058,17 +1058,14 @@ static int local_lremovexattr(FsContext *ctx, V9fsPath *fs_path, static int local_name_to_path(FsContext *ctx, V9fsPath *dir_path, const char *name, V9fsPath *target) { if (dir_path) { - v9fs_string_sprintf((V9fsString *)target, "%s/%s", - dir_path->data, name); + v9fs_path_sprintf(target, "%s/%s", dir_path->data, name); } else { - v9fs_string_sprintf((V9fsString *)target, "%s", name); + v9fs_path_sprintf(target, "%s", name); } - /* Bump the size for including terminating NULL */ - target->size++; return 0; } static int local_renameat(FsContext *ctx, V9fsPath *olddir, const char *old_name, V9fsPath *newdir, diff --git a/hw/9pfs/9p-proxy.c b/hw/9pfs/9p-proxy.c index d091564b6fd2..f2417b7fd73d 100644 --- a/hw/9pfs/9p-proxy.c +++ b/hw/9pfs/9p-proxy.c @@ -1021,17 +1021,14 @@ static int proxy_lremovexattr(FsContext *ctx, V9fsPath *fs_path, static int proxy_name_to_path(FsContext *ctx, V9fsPath *dir_path, const char *name, V9fsPath *target) { if (dir_path) { - v9fs_string_sprintf((V9fsString *)target, "%s/%s", - dir_path->data, name); + v9fs_path_sprintf(target, "%s/%s", dir_path->data, name); } else { - v9fs_string_sprintf((V9fsString *)target, "%s", name); + v9fs_path_sprintf(target, "%s", name); } - /* Bump the size for including terminating NULL */ - target->size++; return 0; } static int proxy_renameat(FsContext *ctx, V9fsPath *olddir, const char *old_name, V9fsPath *newdir, diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index d8f48ca76c47..639f93930285 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -10,10 +10,11 @@ * the COPYING file in the top-level directory. * */ #include "qemu/osdep.h" +#include #include "hw/virtio/virtio.h" #include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/iov.h" #include "qemu/sockets.h" @@ -177,10 +178,24 @@ void v9fs_path_free(V9fsPath *path) g_free(path->data); path->data = NULL; path->size = 0; } + +void GCC_FMT_ATTR(2, 3) +v9fs_path_sprintf(V9fsPath *path, const char *fmt, ...) +{ + va_list ap; + + v9fs_path_free(path); + + va_start(ap, fmt); + /* Bump the size for including terminating NULL */ + path->size = g_vasprintf(&path->data, fmt, ap) + 1; + va_end(ap); +} + void v9fs_path_copy(V9fsPath *lhs, V9fsPath *rhs) { v9fs_path_free(lhs); lhs->data = g_malloc(rhs->size); memcpy(lhs->data, rhs->data, rhs->size); @@ -915,14 +930,12 @@ static void print_sg(struct iovec *sg, int cnt) static void v9fs_fix_path(V9fsPath *dst, V9fsPath *src, int len) { V9fsPath str; v9fs_path_init(&str); v9fs_path_copy(&str, dst); - v9fs_string_sprintf((V9fsString *)dst, "%s%s", src->data, str.data+len); + v9fs_path_sprintf(dst, "%s%s", src->data, str.data + len); v9fs_path_free(&str); - /* +1 to include terminating NULL */ - dst->size++; } static inline bool is_ro_export(FsContext *ctx) { return ctx->export_flags & V9FS_RDONLY; diff --git a/hw/9pfs/9p.h b/hw/9pfs/9p.h index a38603398ef5..d539d2ebe9c0 100644 --- a/hw/9pfs/9p.h +++ b/hw/9pfs/9p.h @@ -325,10 +325,11 @@ static inline uint8_t v9fs_request_cancelled(V9fsPDU *pdu) } extern void v9fs_reclaim_fd(V9fsPDU *pdu); extern void v9fs_path_init(V9fsPath *path); extern void v9fs_path_free(V9fsPath *path); +extern void v9fs_path_sprintf(V9fsPath *path, const char *fmt, ...); extern void v9fs_path_copy(V9fsPath *lhs, V9fsPath *rhs); extern int v9fs_name_to_path(V9fsState *s, V9fsPath *dirpath, const char *name, V9fsPath *path); extern int v9fs_device_realize_common(V9fsState *s, Error **errp); extern void v9fs_device_unrealize_common(V9fsState *s, Error **errp);