From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: stable@dpdk.org, Stephen Hemminger <sthemmin@microsoft.com>
Subject: [dpdk-dev] [PATCH 6/7] bus/vmbus: refactor secondary mapping
Date: Thu, 7 Feb 2019 19:44:06 -0800 [thread overview]
Message-ID: <20190208034407.7865-7-stephen@networkplumber.org> (raw)
In-Reply-To: <20190208034407.7865-1-stephen@networkplumber.org>
From: Stephen Hemminger <sthemmin@microsoft.com>
The secondary mapping function was duplicating the code
used to search the uio_resource list.
Skip the unwinding since map failure already makes device
unusable.
Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
---
drivers/bus/vmbus/vmbus_common_uio.c | 132 ++++++++++++---------------
1 file changed, 58 insertions(+), 74 deletions(-)
diff --git a/drivers/bus/vmbus/vmbus_common_uio.c b/drivers/bus/vmbus/vmbus_common_uio.c
index 9947f82ab194..1aa5cb2e4b92 100644
--- a/drivers/bus/vmbus/vmbus_common_uio.c
+++ b/drivers/bus/vmbus/vmbus_common_uio.c
@@ -23,79 +23,82 @@ static struct rte_tailq_elem vmbus_tailq = {
};
EAL_REGISTER_TAILQ(vmbus_tailq)
-static int
-vmbus_uio_map_secondary(struct rte_vmbus_device *dev)
+struct mapped_vmbus_resource *
+vmbus_uio_find_resource(const struct rte_vmbus_device *dev)
{
- int fd, i;
- struct vmbus_channel *chan;
struct mapped_vmbus_resource *uio_res;
- struct mapped_vmbus_res_list *uio_res_list
- = RTE_TAILQ_CAST(vmbus_tailq.head, mapped_vmbus_res_list);
+ struct mapped_vmbus_res_list *uio_res_list =
+ RTE_TAILQ_CAST(vmbus_tailq.head, mapped_vmbus_res_list);
+
+ if (dev == NULL)
+ return NULL;
TAILQ_FOREACH(uio_res, uio_res_list, next) {
+ if (rte_uuid_compare(uio_res->id, dev->device_id) == 0)
+ return uio_res;
+ }
+ return NULL;
+}
- /* skip this element if it doesn't match our UUID */
- if (rte_uuid_compare(uio_res->id, dev->device_id) != 0)
- continue;
+static int
+vmbus_uio_map_secondary(struct rte_vmbus_device *dev)
+{
+ struct mapped_vmbus_resource *uio_res;
+ struct vmbus_channel *chan;
+ int fd, i;
- /* open /dev/uioX */
- fd = open(uio_res->path, O_RDWR);
- if (fd < 0) {
- VMBUS_LOG(ERR, "Cannot open %s: %s",
- uio_res->path, strerror(errno));
- return -1;
- }
+ uio_res = vmbus_uio_find_resource(dev);
+ if (!uio_res) {
+ VMBUS_LOG(ERR, "Cannot find resource for device");
+ return -1;
+ }
- for (i = 0; i != uio_res->nb_maps; i++) {
- void *mapaddr;
- off_t offset = i * PAGE_SIZE;
+ /* open /dev/uioX */
+ fd = open(uio_res->path, O_RDWR);
+ if (fd < 0) {
+ VMBUS_LOG(ERR, "Cannot open %s: %s",
+ uio_res->path, strerror(errno));
+ return -1;
+ }
- mapaddr = vmbus_map_resource(uio_res->maps[i].addr,
- fd, offset,
- uio_res->maps[i].size, 0);
+ for (i = 0; i != uio_res->nb_maps; i++) {
+ void *mapaddr;
+ off_t offset = i * PAGE_SIZE;
- if (mapaddr == uio_res->maps[i].addr)
- continue;
+ mapaddr = vmbus_map_resource(uio_res->maps[i].addr,
+ fd, offset,
+ uio_res->maps[i].size, 0);
- VMBUS_LOG(ERR,
- "Cannot mmap device resource file %s to address: %p",
- uio_res->path, uio_res->maps[i].addr);
+ if (mapaddr == uio_res->maps[i].addr)
+ continue; /* successful map */
- if (mapaddr != MAP_FAILED)
- /* unmap addr wrongly mapped */
- vmbus_unmap_resource(mapaddr,
- (size_t)uio_res->maps[i].size);
+ if (mapaddr == MAP_FAILED)
+ VMBUS_LOG(ERR,
+ "mmap resource %d in secondary failed", i);
+ else
+ VMBUS_LOG(ERR,
+ "mmap resource %d address mismatch", i);
- /* unmap addrs correctly mapped */
- while (--i >= 0)
- vmbus_unmap_resource(uio_res->maps[i].addr,
- (size_t)uio_res->maps[i].size);
+ close(fd);
+ return -1;
+ }
- close(fd);
- return -1;
- }
+ /* fd is not needed in slave process, close it */
+ close(fd);
- /* fd is not needed in slave process, close it */
- close(fd);
+ dev->primary = uio_res->primary;
+ if (!dev->primary) {
+ VMBUS_LOG(ERR, "missing primary channel");
+ return -1;
+ }
- dev->primary = uio_res->primary;
- if (!dev->primary) {
- VMBUS_LOG(ERR, "missing primary channel");
+ STAILQ_FOREACH(chan, &dev->primary->subchannel_list, next) {
+ if (vmbus_uio_map_secondary_subchan(dev, chan) != 0) {
+ VMBUS_LOG(ERR, "cannot map secondary subchan");
return -1;
}
-
- STAILQ_FOREACH(chan, &dev->primary->subchannel_list, next) {
- if (vmbus_uio_map_secondary_subchan(dev, chan) != 0) {
- VMBUS_LOG(ERR, "cannot map secondary subchan");
- return -1;
- }
- }
-
- return 0;
}
-
- VMBUS_LOG(ERR, "Cannot find resource for device");
- return 1;
+ return 0;
}
static int
@@ -136,25 +139,6 @@ vmbus_uio_map_primary(struct rte_vmbus_device *dev)
return -1;
}
-
-struct mapped_vmbus_resource *
-vmbus_uio_find_resource(const struct rte_vmbus_device *dev)
-{
- struct mapped_vmbus_resource *uio_res;
- struct mapped_vmbus_res_list *uio_res_list =
- RTE_TAILQ_CAST(vmbus_tailq.head, mapped_vmbus_res_list);
-
- if (dev == NULL)
- return NULL;
-
- TAILQ_FOREACH(uio_res, uio_res_list, next) {
- /* skip this element if it doesn't match our VMBUS address */
- if (rte_uuid_compare(uio_res->id, dev->device_id) == 0)
- return uio_res;
- }
- return NULL;
-}
-
/* map the VMBUS resource of a VMBUS device in virtual memory */
int
vmbus_uio_map_resource(struct rte_vmbus_device *dev)
--
2.20.1
next prev parent reply other threads:[~2019-02-08 3:44 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-08 3:44 [dpdk-dev] [PATCH 0/7] vmbus/netvsc: fix multi-process support Stephen Hemminger
2019-02-08 3:44 ` [dpdk-dev] [PATCH 1/7] bus/vmbus: fix secondary process setup Stephen Hemminger
2019-02-08 3:44 ` [dpdk-dev] [PATCH 2/7] net/netvsc: fix VF support with secondary process Stephen Hemminger
2019-02-08 3:44 ` [dpdk-dev] [PATCH 3/7] bus/vmbus: fix check for mmap failure Stephen Hemminger
2019-02-08 3:44 ` [dpdk-dev] [PATCH 4/7] bus/vmbus: stop mapping if empty resource found Stephen Hemminger
2019-02-08 3:44 ` [dpdk-dev] [PATCH 5/7] bus/vmbus: map ring in secondary Stephen Hemminger
2019-02-08 3:44 ` Stephen Hemminger [this message]
2019-02-08 3:44 ` [dpdk-dev] [PATCH 7/7] net/netvsc: remove unnecessary format of ether address Stephen Hemminger
2019-03-29 9:51 ` [dpdk-dev] [dpdk-stable] [PATCH 0/7] vmbus/netvsc: fix multi-process support Thomas Monjalon
2019-03-29 9:51 ` Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190208034407.7865-7-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=dev@dpdk.org \
--cc=stable@dpdk.org \
--cc=sthemmin@microsoft.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).