From patchwork Wed Jun 14 17:19:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 9787025 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 29809602D9 for ; Wed, 14 Jun 2017 17:22:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F27728210 for ; Wed, 14 Jun 2017 17:22:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0416F27E5A; Wed, 14 Jun 2017 17:22:14 +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 25E54283A6 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 1dLBx4-0004Pk-6e; Wed, 14 Jun 2017 17:19:30 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dLBx2-0004PD-NY for xen-devel@lists.xenproject.org; Wed, 14 Jun 2017 17:19:28 +0000 Received: from [85.158.139.211] by server-7.bemta-5.messagelabs.com id EE/C1-02181-02071495; Wed, 14 Jun 2017 17:19:28 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprNIsWRWlGSWpSXmKPExsXitHSDva58gWO kwe33whbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8bBFb1sBV8FKpZ2z2RpYDzL28XIwSEh4C/R /cGpi5GTg01AWeJnZy8biC0ioCfRdOA5I4jNLOAl8WNFDzuILSzgLHFo4S1WEJtFQFWiY/8mZ hCbV8BC4ujybWA1EgLyErvaLrKCjOcUsJRYd9YQJCwEVDK35ysjhK0g0TH9GBNEq6DEyZlPWC BWSUgcfPGCeQIj7ywkqVlIUgsYmVYxahSnFpWlFukamuolFWWmZ5TkJmbm6BoamOrlphYXJ6a n5iQmFesl5+duYgQGDgMQ7GBs2O55iFGSg0lJlHeqoGOkEF9SfkplRmJxRnxRaU5q8SFGGQ4O JQneX3lAOcGi1PTUirTMHGAIw6QlOHiURHhjs4DSvMUFibnFmekQqVOMlhwP/qz7wsSxYfV6I Pns/JYvTEIsefl5qVLivA9A5gmANGSU5sGNg8XZJUZZKWFeRqADhXgKUotyM0tQ5V8xinMwKg nzns0FmsKTmVcCt/UV0EFMQAcFXXAAOagkESEl1cAoN3PLx8zWBcYHd1WvN9hl+3mS39n2wny VD6wtPvzrZk+oM9n5YbFp8uv/J1k69i4P/x9d/X1Fa1nk+S0LV92aYK4/21zhhcLWzLuXJj// rpcuz7G5qnFGbYX3Iv87H6p2lPLzLpE/PCnI8b3LIcfrrQw3WA962Oo7fH8edsqIsbLwi5WP/ wojJZbijERDLeai4kQAXhFyeq4CAAA= X-Env-Sender: prvs=3313ff277=wei.liu2@citrix.com X-Msg-Ref: server-13.tower-206.messagelabs.com!1497460764!87917430!2 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 9900 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="436408890" From: Wei Liu To: Xen-devel Date: Wed, 14 Jun 2017 18:19:21 +0100 Message-ID: <20170614171921.17475-5-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 4/4] XXX a command to test the locking facility 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 | 2 ++ tools/xl/xl_cmdtable.c | 5 +++++ tools/xl/xl_misc.c | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/tools/xl/xl.h b/tools/xl/xl.h index 8d667ff444..9cb135baf2 100644 --- a/tools/xl/xl.h +++ b/tools/xl/xl.h @@ -209,6 +209,8 @@ int main_psr_cat_show(int argc, char **argv); #endif int main_qemu_monitor_command(int argc, char **argv); +int main_lock(int argc, char **argv); + void help(const char *command); extern const char *common_domname; diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c index 30eb93c17f..01db5fb8f4 100644 --- a/tools/xl/xl_cmdtable.c +++ b/tools/xl/xl_cmdtable.c @@ -591,6 +591,11 @@ struct cmd_spec cmd_table[] = { "Issue a qemu monitor command to the device model of a domain", " ", }, + { "lock", + &main_lock, 0, 0, + "Lock a domain, prevent other xl processes from manipulating it", + "", + }, }; int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec); diff --git a/tools/xl/xl_misc.c b/tools/xl/xl_misc.c index 9c6227af23..772fd7adb4 100644 --- a/tools/xl/xl_misc.c +++ b/tools/xl/xl_misc.c @@ -14,6 +14,7 @@ #include #include +#include #include #include @@ -344,6 +345,42 @@ int main_config_update(int argc, char **argv) return 0; } +struct lock_arg { + uint32_t domid; +}; + +static int lock_fn(void *p) +{ + struct lock_arg *arg = p; + + fprintf(stderr, "Now I have the lock for %u\n", arg->domid); + + sleep(10); + + fprintf(stderr, "Done\n"); + + return 0; +} + +int main_lock(int argc, char **argv) +{ + uint32_t domid; + struct lock_arg arg; + int rc; + + domid = find_domain(argv[optind++]); + + fprintf(stderr, "About to lock %u\n", domid); + + arg.domid = domid; + + rc = with_lock(domid, lock_fn, &arg); + fprintf(stderr, "with_lock returned, rc = %d\n", rc); + if (rc) + return EXIT_FAILURE; + return EXIT_SUCCESS; +} + /* * Local variables: * mode: C