From patchwork Mon May 29 13:13:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 768192 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id 3wbxyC2L23z9s5L; Mon, 29 May 2017 23:13:39 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical-com.20150623.gappssmtp.com header.i=@canonical-com.20150623.gappssmtp.com header.b="n+up3tFC"; dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1dFKUK-0004tf-MN; Mon, 29 May 2017 13:13:36 +0000 Received: from mail-qk0-f180.google.com ([209.85.220.180]) by huckleberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1dFKU9-0004nK-F1 for kernel-team@lists.ubuntu.com; Mon, 29 May 2017 13:13:25 +0000 Received: by mail-qk0-f180.google.com with SMTP id u75so47658896qka.3 for ; Mon, 29 May 2017 06:13:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/0tM0NkftNreduQa4Tz5B3E5bzV4nmg7lzsuRwX3MwA=; b=n+up3tFCiuMZ62t730nd4Ve2Ft8Rfu0HBY6jRzc29scZdh4B13IhTGGzFtzZoNdvo7 H09oFQHzCvxeyj5YXhtsxOHxFYYW6CyYWiZZ9wlnZ3COcVOIj5Fxs7+OPIr67WOsCXvx CZKsOX9KhKRQKsIEUgSkX7NQJmuQifSHnJ3wVKrq3ojlw7I5UWdrIktDfjv43hY7RlAn WbYnAT776gDDCiT9tBdlqHbHc2k9x4ApCvgKMfCbXVuEoiHcLOG9wmnQHijffdto0I9j MQ1QEoTR/CQI+AlnZHxERFA/pVBSWGG1MGucKsrwJD5t0AEFiumrZaj1sefQ7xvoslkc uy4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/0tM0NkftNreduQa4Tz5B3E5bzV4nmg7lzsuRwX3MwA=; b=nK7l4jhlLkI1fi9KPlc/uJc78kNxDWAY63ky0PvbtFbDCdUD+vK+D1JWOF5tnCc+wg 09ijKLGylL5D6ZI0/auJAv0RdZEQNOb3YLVApcOEmGC9yS/C7L2Cyju6l8+8hLKFjvVQ 98p9IrFbjY2G8SOmD4EXg1kVDwZN94oaKsiKbyfJvKF9aAcObdvIzNAy/23MwYpxdN1N gBukMMrnlxkN+hpq98UASlyMmcTcs746QF8hTVT/tJjDRjx6IOU3sfMbdJEZwqm6/QeB Q7cFIRGRMfjWWuPaTastV95rczBGArcKqnhKKBu8LdX7qNgZcOrCse/9K0/bJX60cnHi nyQw== X-Gm-Message-State: AODbwcAO0T8rBvx0SxrK2VIDEU5yhPhjzB7b8mYdrGQDZLcJ/cX1sb0A f2ZFY0vujsBJDaay2LI= X-Received: by 10.233.223.197 with SMTP id t188mr15818386qkf.203.1496063604123; Mon, 29 May 2017 06:13:24 -0700 (PDT) Received: from localhost.localdomain (189-19-112-107.dsl.telesp.net.br. [189.19.112.107]) by smtp.gmail.com with ESMTPSA id t35sm6324779qta.62.2017.05.29.06.13.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 29 May 2017 06:13:23 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com, jopoulso@microsoft.com Subject: [azure][PATCH 4/4] UBUNTU: SAUCE: 9p: net/9p: add hv_sock transport Date: Mon, 29 May 2017 10:13:02 -0300 Message-Id: <1496063582-25160-5-git-send-email-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1496063582-25160-1-git-send-email-marcelo.cerri@canonical.com> References: <1496063582-25160-1-git-send-email-marcelo.cerri@canonical.com> Cc: Cheng-mean Liu X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: kernel-team-bounces@lists.ubuntu.com From: Cheng-mean Liu BugLink: http://bugs.launchpad.net/bugs/1690196 Add support for Hyper-V socket transport to net/9p. Signed-off-by: Cheng-mean Liu (Minor cleanups and coding style fixes) Signed-off-by: Marcelo Henrique Cerri --- net/9p/trans_fd.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c index 7bc2208b6cc4..b12c45a0f32b 100644 --- a/net/9p/trans_fd.c +++ b/net/9p/trans_fd.c @@ -155,6 +155,26 @@ struct p9_trans_fd { struct p9_conn conn; }; +// structures and defines for Hyperv socket +#define HV_PROTOCOL_RAW 1 + +// SOCKADDR_HV.VmId +#define HV_GUID_PARENT UUID_LE(0xa42e7cda, 0xd03f, 0x480c, 0x9c, 0xc2, 0xa4, \ + 0xde, 0x20, 0xab, 0xb8, 0x78) + +// SOCKADDR_HV.VmId: service Id used for Hyper-V socket communication between +// the guest and its host. The last two bytes from the port parameters in the +// mount option replace the last two bytes in HV_SERVICE_ID_TEMPLATE +#define HV_SERVICE_ID_TEMPLATE UUID_LE(0xBCEf5661, 0x84A1, 0x4E44, 0x85, 0x6B, \ + 0x62, 0x45, 0xE6, 0x9f, 0x00, 0x00) + +struct sockaddr_hv { + __kernel_sa_family_t family; + unsigned short reserved; + uuid_le vm_id; + uuid_le service_id; +}; + static void p9_poll_workfn(struct work_struct *work); static DEFINE_SPINLOCK(p9_poll_lock); @@ -1035,6 +1055,82 @@ p9_fd_create(struct p9_client *client, const char *addr, char *args) return 0; } +static int +p9_fd_create_hv(struct p9_client *client, const char *addr, char *args) +{ + int err; + struct socket *csocket; + struct sockaddr_hv server_socket_addr; + struct p9_fd_opts opts; + + err = parse_opts(args, &opts); + if (err < 0) + return err; + + csocket = NULL; + + // for debugging purpose only + // pr_err("%s:%s\n", __func__, addr); + // kgdb_breakpoint(); + + // create socket + err = __sock_create(current->nsproxy->net_ns, + AF_HYPERV, + SOCK_STREAM, + HV_PROTOCOL_RAW, + &csocket, 1); + if (err) { + pr_err("%s:__sock_create (%d): problem creating socket (err=%d)\n", + __func__, task_pid_nr(current), err); + return err; + } + + // server socket address information + memset((char *)&server_socket_addr, 0, sizeof(struct sockaddr_hv)); + server_socket_addr.family = AF_HYPERV; + server_socket_addr.vm_id = HV_GUID_PARENT; + + // create service id from the input port number + server_socket_addr.service_id = HV_SERVICE_ID_TEMPLATE; + + server_socket_addr.service_id.b[14] = (__u8)((opts.port & 0xff00) >> 8); + server_socket_addr.service_id.b[15] = (__u8)(opts.port & 0x00ff); + + pr_err("%s: service_id:(hex) %x%x%x%x-%x%x-%x%x-%x%x-%x%x%x%x%x%x\n", + __func__, + server_socket_addr.service_id.b[3], //DWORD + server_socket_addr.service_id.b[2], + server_socket_addr.service_id.b[1], + server_socket_addr.service_id.b[0], + server_socket_addr.service_id.b[5], //WORD + server_socket_addr.service_id.b[4], + server_socket_addr.service_id.b[7], + server_socket_addr.service_id.b[6], + server_socket_addr.service_id.b[9], //WORD + server_socket_addr.service_id.b[8], + server_socket_addr.service_id.b[10], //Bytes + server_socket_addr.service_id.b[11], + server_socket_addr.service_id.b[12], + server_socket_addr.service_id.b[13], + server_socket_addr.service_id.b[14], + server_socket_addr.service_id.b[15]); + + err = csocket->ops->connect(csocket, + (struct sockaddr *)&server_socket_addr, + sizeof(struct sockaddr_hv), 0); + if (err < 0) { + pr_err("%s:connect (%d): problem connecting socket to %s (err = %d)\n", + __func__, task_pid_nr(current), addr, err); + sock_release(csocket); + return err; + } + + err = p9_socket_open(client, csocket); + if (err < 0) + pr_err("%s: p9_socket_open failed\n", __func__); + return err; +} + static struct p9_trans_module p9_tcp_trans = { .name = "tcp", .maxsize = MAX_SOCK_BUF, @@ -1071,6 +1167,18 @@ static struct p9_trans_module p9_fd_trans = { .owner = THIS_MODULE, }; +static struct p9_trans_module p9_hv_trans = { + .name = "hyperv", + .maxsize = MAX_SOCK_BUF, + .def = 0, + .create = p9_fd_create_hv, + .close = p9_fd_close, + .request = p9_fd_request, + .cancel = p9_fd_cancel, + .cancelled = p9_fd_cancelled, + .owner = THIS_MODULE, +}; + /** * p9_poll_proc - poll worker thread * @a: thread state and arguments @@ -1108,6 +1216,7 @@ int p9_trans_fd_init(void) v9fs_register_trans(&p9_tcp_trans); v9fs_register_trans(&p9_unix_trans); v9fs_register_trans(&p9_fd_trans); + v9fs_register_trans(&p9_hv_trans); return 0; } @@ -1118,4 +1227,5 @@ void p9_trans_fd_exit(void) v9fs_unregister_trans(&p9_tcp_trans); v9fs_unregister_trans(&p9_unix_trans); v9fs_unregister_trans(&p9_fd_trans); + v9fs_unregister_trans(&p9_hv_trans); }