From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9258F45BB4; Wed, 23 Oct 2024 18:07:34 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B4272402C6; Wed, 23 Oct 2024 18:07:33 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 55570400D5 for ; Wed, 23 Oct 2024 18:07:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729699651; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Vq3N5geeg+D+1EQfA9dzJX/uXEGFNBaeDu4zoKEtshU=; b=II6fPvUtt02yZOhB0y4NoKmQa/z7UuDKwpgeKP94N+OssPPDU4x3f5f0RmGyKmYrtNdh1D xsh85MqhG7c97rK2DfRM7wENGBN8XsCuZroU8HzXPW0frPGJ/saKHBh215QtPUgmOecp3A eBqLMoWAccPsPZbjtQdUTn0TInpJ/8Q= Received: from mail-lf1-f71.google.com (mail-lf1-f71.google.com [209.85.167.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-261-ywroYOcMO--hBn4Djh1Bug-1; Wed, 23 Oct 2024 12:07:30 -0400 X-MC-Unique: ywroYOcMO--hBn4Djh1Bug-1 Received: by mail-lf1-f71.google.com with SMTP id 2adb3069b0e04-539ec1a590fso5650888e87.0 for ; Wed, 23 Oct 2024 09:07:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729699649; x=1730304449; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Vq3N5geeg+D+1EQfA9dzJX/uXEGFNBaeDu4zoKEtshU=; b=hoO7ZCZa7avS34kqle8lBgLhZo53F2ggIXvYXfxW7VQmoLrnJLL7jzEe/3UojLog2J L00M03IqnHIxm4IQEWdMWaNNMCQeKtFkXJk1EiA/nCKavI5juSla8+KrNlfdUBdQ5TlL 6OvcU0PUSj1UDanHellkXJr3rnOlTqsyKhgzShBS0oY1oEuVVmVKs1qqvjS8lageC7Bv jghLsd63v15N4fh60Qxh5YGHic2d/byvVj7IIvxnpUFI8UvDsUnbpzMjhDk+WJCP4Rzy +fM2gsHu32ITnC9gGYYaPo89BclJSroeiotpH8BMEm5CwaAQ58PX+FIX6KFiqy3FuVfO 1K9w== X-Gm-Message-State: AOJu0YxZW3r7X4jUTjlkCGSDIcWqy1RW8asK3qoHqshIIUts/Rd8L1ME ATzwlQa5LQHRgGmo2MCDKeOecZRKqdw9G1u1ZxqfHNqTczWA3S7UbcHl0+8eG3RlZhnIVpipZl8 eokSfj6EC/sg/066uOlqKkWth8ELBh0sLc66nJYPpQm5b+4F4CbgaHP7fgvpJiKzQx8njrF58Qt ucvB0ZA+nSfWKCMRw= X-Received: by 2002:a05:6512:1582:b0:539:e4b5:10e5 with SMTP id 2adb3069b0e04-53b1a31d79dmr1814886e87.9.1729699648885; Wed, 23 Oct 2024 09:07:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEaCoEfLaDyY2jDD0k0mPm63L09EtlZELby/i0ip7N5ckbyfU6+zZPMdhsB1uKRdL9iLrjnYUeeiZBJ4Q9k/eE= X-Received: by 2002:a05:6512:1582:b0:539:e4b5:10e5 with SMTP id 2adb3069b0e04-53b1a31d79dmr1814863e87.9.1729699648432; Wed, 23 Oct 2024 09:07:28 -0700 (PDT) MIME-Version: 1.0 References: <20241023151552.2863387-1-maxime.coquelin@redhat.com> <20241023151552.2863387-5-maxime.coquelin@redhat.com> In-Reply-To: <20241023151552.2863387-5-maxime.coquelin@redhat.com> From: David Marchand Date: Wed, 23 Oct 2024 18:07:17 +0200 Message-ID: Subject: Re: [PATCH 4/6] vhost: refactor VDUSE reconnection log mapping To: Maxime Coquelin Cc: dev@dpdk.org, chenbox@nvidia.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Wed, Oct 23, 2024 at 5:16=E2=80=AFPM Maxime Coquelin wrote: > > This patch moves the VDUSE reconnection log mapping, as > well as creation if needed, into a dedicated function. > > This is a preliminary rework to simplify VDUSE device > creation. > > Signed-off-by: Maxime Coquelin > --- > lib/vhost/vduse.c | 138 +++++++++++++++++++++++++--------------------- > 1 file changed, 75 insertions(+), 63 deletions(-) > > diff --git a/lib/vhost/vduse.c b/lib/vhost/vduse.c > index c8c4761293..985d4cc58d 100644 > --- a/lib/vhost/vduse.c > +++ b/lib/vhost/vduse.c > @@ -431,6 +431,9 @@ vduse_reconnect_path_init(void) > const char *directory; > int ret; > > + if (vduse_reconnect_path_set =3D=3D true) > + return 0; > + > /* from RuntimeDirectory=3D see systemd.exec */ > directory =3D getenv("RUNTIME_DIRECTORY"); > if (directory =3D=3D NULL) { > @@ -462,9 +465,74 @@ vduse_reconnect_path_init(void) > VHOST_CONFIG_LOG("vduse", INFO, "Created VDUSE reconnect director= y in %s", > vduse_reconnect_dir); > > + vduse_reconnect_path_set =3D true; > + > return 0; > } > > +static int > +vduse_reconnect_log_map(const char *dev_name, struct vhost_reconnect_dat= a **reco_log, bool create) You can pass struct virtio_net *dev instead of patch 6. > +{ > + char reco_file[PATH_MAX]; > + int fd, ret; > + > + if (vduse_reconnect_path_init() < 0) { > + VHOST_CONFIG_LOG(dev_name, ERR, "Failed to initialize rec= onnect path"); > + return -1; Weird indent. > + } > + > + ret =3D snprintf(reco_file, sizeof(reco_file), "%s/%s", vduse_rec= onnect_dir, dev_name); > + if (ret < 0 || ret =3D=3D sizeof(reco_file)) { > + VHOST_CONFIG_LOG(dev_name, ERR, "Failed to create vduse r= econnect path name"); > + return -1; > + } > + > + if (create) { > + fd =3D open(reco_file, O_CREAT | O_EXCL | O_RDWR, 0600); > + if (fd < 0) { > + if (errno =3D=3D EEXIST) { > + VHOST_CONFIG_LOG(dev_name, ERR, "Reconnec= t file %s exists but not the device", > + reco_file); > + } else { > + VHOST_CONFIG_LOG(dev_name, ERR, "Failed t= o open reconnect file %s (%s)", > + reco_file, strerror(errno= )); > + } > + return -1; > + } > + > + ret =3D ftruncate(fd, sizeof(**reco_log)); > + if (ret < 0) { > + VHOST_CONFIG_LOG(dev_name, ERR, "Failed to trunca= te reconnect file %s (%s)", > + reco_file, strerror(errno)); > + goto out_close; > + } > + } else { > + fd =3D open(reco_file, O_RDWR, 0600); > + if (fd < 0) { > + if (errno =3D=3D ENOENT) > + VHOST_CONFIG_LOG(dev_name, ERR, "Missing = reconnect file (%s)", reco_file); > + else > + VHOST_CONFIG_LOG(dev_name, ERR, "Failed t= o open reconnect file %s (%s)", > + reco_file, strerror(errno= )); > + return -1; > + } > + } > + > + *reco_log =3D mmap(NULL, sizeof(**reco_log), PROT_READ | PROT_WRI= TE, MAP_SHARED, fd, 0); > + if (*reco_log =3D=3D MAP_FAILED) { > + VHOST_CONFIG_LOG(dev_name, ERR, "Failed to mmap reconnect= file %s (%s)", > + reco_file, strerror(errno)); > + ret =3D -1; > + goto out_close; > + } > + ret =3D 0; > + > +out_close: > + close(fd); > + > + return ret; > +} > + > static void > vduse_reconnect_handler(int fd, void *arg, int *remove) > { > @@ -519,7 +587,7 @@ vduse_reconnect_start_device(struct virtio_net *dev) > int > vduse_device_create(const char *path, bool compliant_ol_flags) > { > - int control_fd, dev_fd, vid, ret, reco_fd; > + int control_fd, dev_fd, vid, ret; > uint32_t i, max_queue_pairs, total_queues; > struct virtio_net *dev; > struct virtio_net_config vnet_config =3D {{ 0 }}; > @@ -527,7 +595,6 @@ vduse_device_create(const char *path, bool compliant_= ol_flags) > uint64_t features; > struct vduse_dev_config *dev_config =3D NULL; > const char *name =3D path + strlen("/dev/vduse/"); > - char reconnect_file[PATH_MAX]; > struct vhost_reconnect_data *reconnect_log =3D MAP_FAILED; > bool reconnect =3D false; > > @@ -539,20 +606,6 @@ vduse_device_create(const char *path, bool compliant= _ol_flags) > } > } > > - if (vduse_reconnect_path_set =3D=3D false) { > - if (vduse_reconnect_path_init() < 0) { > - VHOST_CONFIG_LOG(path, ERR, "failed to initialize= reconnect path"); > - return -1; > - } > - vduse_reconnect_path_set =3D true; > - } > - > - ret =3D snprintf(reconnect_file, sizeof(reconnect_file), "%s/%s",= vduse_reconnect_dir, name); > - if (ret < 0 || ret =3D=3D sizeof(reconnect_file)) { > - VHOST_CONFIG_LOG(name, ERR, "Failed to create vduse recon= nect path name"); > - return -1; > - } > - > control_fd =3D open(VDUSE_CTRL_PATH, O_RDWR); > if (control_fd < 0) { > VHOST_CONFIG_LOG(name, ERR, "Failed to open %s: %s", > @@ -592,26 +645,10 @@ vduse_device_create(const char *path, bool complian= t_ol_flags) > VHOST_CONFIG_LOG(name, INFO, "Device already exists, reco= nnecting..."); > reconnect =3D true; > > - reco_fd =3D open(reconnect_file, O_RDWR, 0600); > - if (reco_fd < 0) { > - if (errno =3D=3D ENOENT) > - VHOST_CONFIG_LOG(name, ERR, "Missing reco= nnect file (%s)", > - reconnect_file); > - else > - VHOST_CONFIG_LOG(name, ERR, "Failed to op= en reconnect file %s (%s)", > - reconnect_file, strerror(= errno)); > - ret =3D -1; > - goto out_dev_close; > - } > - > - reconnect_log =3D mmap(NULL, sizeof(*reconnect_log), PROT= _READ | PROT_WRITE, > - MAP_SHARED, reco_fd, 0); > - close(reco_fd); > - if (reconnect_log =3D=3D MAP_FAILED) { > - VHOST_CONFIG_LOG(name, ERR, "Failed to mmap recon= nect file %s (%s)", > - reconnect_file, strerror(errno)); > - ret =3D -1; > - goto out_dev_close; > + ret =3D vduse_reconnect_log_map(name, &reconnect_log, fal= se); > + if (ret < 0) { > + VHOST_CONFIG_LOG(name, ERR, "Failed to map reconn= ect log file"); No additional log, all error cases are covered, afaics. > + goto out_ctrl_close; > } > > if (reconnect_log->version !=3D VHOST_RECONNECT_VERSION) = { --=20 David Marchand