From: Benjamin Marzinski <bmarzins@redhat.com>
To: Christophe Varoqui <christophe.varoqui@opensvc.com>
Cc: device-mapper development <dm-devel@redhat.com>,
Martin Wilck <Martin.Wilck@suse.com>
Subject: [PATCH v2 2/5] libmultipath: turn pp->vpd_data into a pointer
Date: Wed, 19 Feb 2020 14:21:42 -0600 [thread overview]
Message-ID: <1582143705-20886-3-git-send-email-bmarzins@redhat.com> (raw)
In-Reply-To: <1582143705-20886-1-git-send-email-bmarzins@redhat.com>
Instead of always allocating space in the path structure for vpd_data,
only allocte it when necessary.
Also, fix comments on vpd tests
Reviewed-by: Martin Wilck <mwilck@suse.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
libmultipath/discovery.c | 17 +++++++++++++++--
libmultipath/print.c | 4 ++--
libmultipath/structs.c | 3 +++
libmultipath/structs.h | 2 +-
tests/vpd.c | 3 ++-
5 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
index 23a7889c..ee3290cd 100644
--- a/libmultipath/discovery.c
+++ b/libmultipath/discovery.c
@@ -1649,8 +1649,21 @@ scsi_ioctl_pathinfo (struct path * pp, int mask)
select_vpd_vendor_id(pp);
vpd_id = pp->vpd_vendor_id;
- if (vpd_id != VPD_VP_UNDEF && get_vpd_sgio(pp->fd, vpd_vendor_pages[vpd_id].pg, vpd_id, pp->vpd_data, sizeof(pp->vpd_data)) < 0)
- condlog(3, "%s: failed to get extra vpd data", pp->dev);
+ if (vpd_id != VPD_VP_UNDEF) {
+ char vpd_data[VPD_DATA_SIZE] = {0};
+
+ if (get_vpd_sgio(pp->fd, vpd_vendor_pages[vpd_id].pg, vpd_id,
+ vpd_data, sizeof(vpd_data)) < 0)
+ condlog(3, "%s: failed to get extra vpd data", pp->dev);
+ else {
+ vpd_data[VPD_DATA_SIZE - 1] = '\0';
+ if (pp->vpd_data)
+ free(pp->vpd_data);
+ pp->vpd_data = strdup(vpd_data);
+ if (!pp->vpd_data)
+ condlog(0, "%s: failed to allocate space for vpd data", pp->dev);
+ }
+ }
parent = pp->udev;
while (parent) {
diff --git a/libmultipath/print.c b/libmultipath/print.c
index 56f86b2f..b944ef32 100644
--- a/libmultipath/print.c
+++ b/libmultipath/print.c
@@ -371,7 +371,7 @@ snprint_multipath_vpd_data(char * buff, size_t len,
vector_foreach_slot(mpp->pg, pgp, i)
vector_foreach_slot(pgp->paths, pp, j)
- if (strlen(pp->vpd_data))
+ if (pp->vpd_data)
return snprintf(buff, len, "%s", pp->vpd_data);
return snprintf(buff, len, "[undef]");
}
@@ -710,7 +710,7 @@ snprint_path_marginal(char * buff, size_t len, const struct path * pp)
static int
snprint_path_vpd_data(char * buff, size_t len, const struct path * pp)
{
- if (strlen(pp->vpd_data) > 0)
+ if (pp->vpd_data)
return snprintf(buff, len, "%s", pp->vpd_data);
return snprintf(buff, len, "[undef]");
}
diff --git a/libmultipath/structs.c b/libmultipath/structs.c
index cc931e4e..2dd378c4 100644
--- a/libmultipath/structs.c
+++ b/libmultipath/structs.c
@@ -131,6 +131,9 @@ free_path (struct path * pp)
udev_device_unref(pp->udev);
pp->udev = NULL;
}
+ if (pp->vpd_data)
+ free(pp->vpd_data);
+
vector_free(pp->hwe);
FREE(pp);
diff --git a/libmultipath/structs.h b/libmultipath/structs.h
index b7a01220..9bd39eb1 100644
--- a/libmultipath/structs.h
+++ b/libmultipath/structs.h
@@ -269,7 +269,7 @@ struct path {
char rev[PATH_REV_SIZE];
char serial[SERIAL_SIZE];
char tgt_node_name[NODE_NAME_SIZE];
- char vpd_data[VPD_DATA_SIZE];
+ char *vpd_data;
unsigned long long size;
unsigned int checkint;
unsigned int tick;
diff --git a/tests/vpd.c b/tests/vpd.c
index 0331c487..3cbad811 100644
--- a/tests/vpd.c
+++ b/tests/vpd.c
@@ -520,8 +520,9 @@ static void test_vpd_eui_ ## len ## _ ## wlen ## _ ## sml(void **state) \
n = create_vpd83(vt->vpdbuf, sizeof(vt->vpdbuf), test_id, \
2, 0, len); \
if (sml) { \
- /* overwrite the page side to DEFAULT_SGIO_LEN + 1 */ \
+ /* overwrite the page size to DEFAULT_SGIO_LEN + 1 */ \
put_unaligned_be16(255, vt->vpdbuf + 2); \
+ /* this causes get_vpd_sgio to do a second ioctl */ \
will_return(__wrap_ioctl, n); \
will_return(__wrap_ioctl, vt->vpdbuf); \
} \
--
2.17.2
next prev parent reply other threads:[~2020-02-19 20:21 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-19 20:21 [PATCH v2 0/5] Multipath Follow-up patches Benjamin Marzinski
2020-02-19 20:21 ` [PATCH v2 1/5] multipath: fix issues found by compiling with gcc 10 Benjamin Marzinski
2020-02-19 20:39 ` Martin Wilck
2020-12-02 13:54 ` [dm-devel] " Martin Wilck
2020-12-03 20:52 ` Benjamin Marzinski
2020-02-19 20:21 ` Benjamin Marzinski [this message]
2020-02-19 20:21 ` [PATCH v2 3/5] libmultipath: change loading and resetting in directio Benjamin Marzinski
2020-02-19 20:21 ` [PATCH v2 4/5] libmultipath: change directio get_events() timeout handling Benjamin Marzinski
2020-02-19 20:21 ` [PATCH v2 5/5] libmultipath: cleanup old issues with directio checker Benjamin Marzinski
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=1582143705-20886-3-git-send-email-bmarzins@redhat.com \
--to=bmarzins@redhat.com \
--cc=Martin.Wilck@suse.com \
--cc=christophe.varoqui@opensvc.com \
--cc=dm-devel@redhat.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).