From patchwork Wed Jun 14 17:19:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 9787021 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 64932602D9 for ; Wed, 14 Jun 2017 17:22:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A94B27E5A for ; Wed, 14 Jun 2017 17:22:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3F69A28417; Wed, 14 Jun 2017 17:22:13 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E230F27E5A for ; Wed, 14 Jun 2017 17:22:12 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dLBx3-0004PO-PN; Wed, 14 Jun 2017 17:19:29 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dLBx1-0004P7-Oj for xen-devel@lists.xenproject.org; Wed, 14 Jun 2017 17:19:27 +0000 Received: from [85.158.139.211] by server-2.bemta-5.messagelabs.com id 7D/2F-02006-F1071495; Wed, 14 Jun 2017 17:19:27 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupnkeJIrShJLcpLzFFi42JxWrrBXleuwDH S4MJuOYvvWyYzOTB6HP5whSWAMYo1My8pvyKBNePGxX7WgmO8FT2HtrE1MO7k7mLk4JAQ8JeY dDO5i5GTg01AWeJnZy8biC0ioCfRdOA5I4jNLOAl8WNFDzuILSwQKXHpzh8mEJtFQFXi+uYeV hCbV8BCon3uVRYQW0JAXmJX20VWkPGcApYS684agoSFgErm9nxlhLAVJDqmH2OCaBWUODnzCQ vEKgmJgy9eME9g5J2FJDULSWoBI9MqRo3i1KKy1CJdQ1O9pKLM9IyS3MTMHF1DA1O93NTi4sT 01JzEpGK95PzcTYzAwGEAgh2MDds9DzFKcjApifJOFXSMFOJLyk+pzEgszogvKs1JLT7EKMPB oSTB+ysPKCdYlJqeWpGWmQMMYZi0BAePkghvbBZQmre4IDG3ODMdInWKUZdjw+r1X5iEWPLy8 1KlxHkfgMwQACnKKM2DGwGLp0uMslLCvIxARwnxFKQW5WaWoMq/YhTnYFQS5j2bCzSFJzOvBG 7TK6AjmICOCLrgAHJESSJCSqqB0UZ0SYDe/stHzlVZs14JcBDZ842/VunBq5e2Z56U5VZMfnz hlojStLsvj1TJ1nNH2uqsin+Ut+67zfYvHyZNMKn/ye6QME2Z/7nIYemVihv4ntpcnbUt49xG Q9G8HuOwOLM+mbu6OwT/rTuwMn3SSvVbX/Mux76wOnzqwFkrNSPmrlUK0u8KjyqxFGckGmoxF xUnAgAY7R3HogIAAA== X-Env-Sender: prvs=3313ff277=wei.liu2@citrix.com X-Msg-Ref: server-13.tower-206.messagelabs.com!1497460764!87917430!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 9845 invoked from network); 14 Jun 2017 17:19:26 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-13.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 14 Jun 2017 17:19:26 -0000 X-IronPort-AV: E=Sophos;i="5.39,341,1493683200"; d="scan'208";a="436408884" From: Wei Liu To: Xen-devel Date: Wed, 14 Jun 2017 18:19:20 +0100 Message-ID: <20170614171921.17475-4-wei.liu2@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170614171921.17475-1-wei.liu2@citrix.com> References: <20170614171921.17475-1-wei.liu2@citrix.com> MIME-Version: 1.0 Cc: Wei Liu , Ian Jackson Subject: [Xen-devel] [RFC PATCH 3/4] xl: introduce facility to run function with per-domain lock held X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Wei Liu --- tools/xl/xl.h | 1 + tools/xl/xl_utils.c | 19 +++++++++++++++++++ tools/xl/xl_utils.h | 3 +++ 3 files changed, 23 insertions(+) diff --git a/tools/xl/xl.h b/tools/xl/xl.h index 93ec4d7e4c..8d667ff444 100644 --- a/tools/xl/xl.h +++ b/tools/xl/xl.h @@ -292,6 +292,7 @@ extern void printf_info_sexp(int domid, libxl_domain_config *d_config, FILE *fh) #define XL_GLOBAL_CONFIG XEN_CONFIG_DIR "/xl.conf" #define XL_LOCK_FILE XEN_LOCK_DIR "/xl" +#define XL_DOMAIN_LOCK_FILE_FMT XEN_LOCK_DIR "/xl-%u" #endif /* XL_H */ diff --git a/tools/xl/xl_utils.c b/tools/xl/xl_utils.c index e7038ec324..bb32ba0a1f 100644 --- a/tools/xl/xl_utils.c +++ b/tools/xl/xl_utils.c @@ -27,6 +27,25 @@ #include "xl.h" #include "xl_utils.h" +int with_lock(uint32_t domid, domain_fn fn, void *arg) +{ + char filename[sizeof(XL_DOMAIN_LOCK_FILE_FMT)+15]; + int fd_lock = -1; + int rc; + + snprintf(filename, sizeof(filename), XL_DOMAIN_LOCK_FILE_FMT, domid); + + rc = acquire_lock(filename, &fd_lock); + if (rc) goto out; + + rc = fn(arg); + + release_lock(filename, &fd_lock); + +out: + return rc; +} + void dolog(const char *file, int line, const char *func, char *fmt, ...) { va_list ap; diff --git a/tools/xl/xl_utils.h b/tools/xl/xl_utils.h index 18280d7e84..5e0d502fa6 100644 --- a/tools/xl/xl_utils.h +++ b/tools/xl/xl_utils.h @@ -149,6 +149,9 @@ int do_daemonize(char *name, const char *pidfile); int acquire_lock(const char *lockfile, int *fd_lock); int release_lock(const char *lockfile, int *fd_lock); + +typedef int (*domain_fn)(void *arg); +int with_lock(uint32_t domid, domain_fn fn, void *arg); #endif /* XL_UTILS_H */ /*