Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/xen change xenbus_read() interface so that caller s...
details: https://anonhg.NetBSD.org/src/rev/ad5b96f00bc7
branches: trunk
changeset: 1008970:ad5b96f00bc7
user: jdolecek <jdolecek%NetBSD.org@localhost>
date: Tue Apr 07 11:47:05 2020 +0000
description:
change xenbus_read() interface so that caller supplies the buffer and it's
size, caller doesn't free(9) the returned value any more
diffstat:
sys/arch/xen/include/xenbus.h | 18 +------
sys/arch/xen/xen/if_xennet_xenbus.c | 38 +++------------
sys/arch/xen/xen/pciback.c | 12 ++---
sys/arch/xen/xen/shutdown_xenbus.c | 14 ++---
sys/arch/xen/xen/xbd_xenbus.c | 26 +----------
sys/arch/xen/xen/xbdback_xenbus.c | 18 +++----
sys/arch/xen/xen/xennetback_xenbus.c | 17 +++---
sys/arch/xen/xen/xpci_xenbus.c | 20 +++----
sys/arch/xen/xenbus/xenbus_probe.c | 28 ++++-------
sys/arch/xen/xenbus/xenbus_xs.c | 84 +++++++++---------------------------
10 files changed, 79 insertions(+), 196 deletions(-)
diffs (truncated from 760 to 300 lines):
diff -r c9b93a1031b2 -r ad5b96f00bc7 sys/arch/xen/include/xenbus.h
--- a/sys/arch/xen/include/xenbus.h Tue Apr 07 11:12:25 2020 +0000
+++ b/sys/arch/xen/include/xenbus.h Tue Apr 07 11:47:05 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: xenbus.h,v 1.15 2020/04/07 09:18:00 jdolecek Exp $ */
+/* $NetBSD: xenbus.h,v 1.16 2020/04/07 11:47:05 jdolecek Exp $ */
/******************************************************************************
* xenbus.h
*
@@ -78,7 +78,7 @@
struct xenbus_device {
SLIST_ENTRY(xenbus_device) xbusd_entries;
- char *xbusd_otherend; /* the otherend path */
+ char xbusd_otherend[64]; /* the otherend path (size arbitrary) */
int xbusd_otherend_id; /* the otherend's id */
/* callback for otherend change */
void (*xbusd_otherend_changed)(void *, XenbusState);
@@ -118,9 +118,8 @@
int xenbus_directory(struct xenbus_transaction *t,
const char *dir, const char *node, unsigned int *num,
char ***);
-int xenbus_read(struct xenbus_transaction *t,
- const char *dir, const char *node, unsigned int *len,
- char **);
+int xenbus_read(struct xenbus_transaction *,
+ const char *, const char *, char *, size_t);
int xenbus_read_ul(struct xenbus_transaction *,
const char *, const char *, unsigned long *, int);
int xenbus_read_ull(struct xenbus_transaction *,
@@ -135,20 +134,11 @@
struct xenbus_transaction *xenbus_transaction_start(void);
int xenbus_transaction_end(struct xenbus_transaction *t, int abort);
-/* Single read and scanf: returns -errno or num scanned if > 0. */
-int xenbus_scanf(struct xenbus_transaction *t,
- const char *dir, const char *node, const char *fmt, ...)
- __attribute__((format(scanf, 4, 5)));
-
/* Single printf and write: returns -errno or 0. */
int xenbus_printf(struct xenbus_transaction *t,
const char *dir, const char *node, const char *fmt, ...)
__attribute__((format(printf, 4, 5)));
-/* Generic read function: NULL-terminated triples of name,
- * sprintf-style type string, and pointer. Returns 0 or errno.*/
-int xenbus_gather(struct xenbus_transaction *t, const char *dir, ...);
-
/* notifer routines for when the xenstore comes up */
// XXX int register_xenstore_notifier(struct notifier_block *nb);
// XXX void unregister_xenstore_notifier(struct notifier_block *nb);
diff -r c9b93a1031b2 -r ad5b96f00bc7 sys/arch/xen/xen/if_xennet_xenbus.c
--- a/sys/arch/xen/xen/if_xennet_xenbus.c Tue Apr 07 11:12:25 2020 +0000
+++ b/sys/arch/xen/xen/if_xennet_xenbus.c Tue Apr 07 11:47:05 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_xennet_xenbus.c,v 1.108 2020/04/06 19:58:09 jdolecek Exp $ */
+/* $NetBSD: if_xennet_xenbus.c,v 1.109 2020/04/07 11:47:06 jdolecek Exp $ */
/*
* Copyright (c) 2006 Manuel Bouyer.
@@ -81,7 +81,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.108 2020/04/06 19:58:09 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.109 2020/04/07 11:47:06 jdolecek Exp $");
#include "opt_xen.h"
#include "opt_nfs_boot.h"
@@ -268,9 +268,10 @@
netif_tx_sring_t *tx_ring;
netif_rx_sring_t *rx_ring;
RING_IDX i;
- char *val, *e, *p;
+ char *e, *p;
unsigned long uval;
extern int ifqmaxlen; /* XXX */
+ char mac[32];
#ifdef XENNET_DEBUG
char **dir;
int dir_n = 0;
@@ -280,28 +281,6 @@
aprint_normal(": Xen Virtual Network Interface\n");
sc->sc_dev = self;
-#ifdef XENNET_DEBUG
- printf("path: %s\n", xa->xa_xbusd->xbusd_path);
- snprintf(id_str, sizeof(id_str), "%d", xa->xa_id);
- err = xenbus_directory(NULL, "device/vif", id_str, &dir_n, &dir);
- if (err) {
- aprint_error_dev(self, "xenbus_directory err %d\n", err);
- } else {
- printf("%s/\n", xa->xa_xbusd->xbusd_path);
- for (i = 0; i < dir_n; i++) {
- printf("\t/%s", dir[i]);
- err = xenbus_read(NULL, xa->xa_xbusd->xbusd_path,
- dir[i], NULL, &val);
- if (err) {
- aprint_error_dev(self, "xenbus_read err %d\n",
- err);
- } else {
- printf(" = %s\n", val);
- free(val, M_DEVBUF);
- }
- }
- }
-#endif /* XENNET_DEBUG */
sc->sc_xbusd = xa->xa_xbusd;
sc->sc_xbusd->xbusd_otherend_changed = xennet_backend_changed;
@@ -340,22 +319,21 @@
}
/* read mac address */
- err = xenbus_read(NULL, sc->sc_xbusd->xbusd_path, "mac", NULL, &val);
+ err = xenbus_read(NULL, sc->sc_xbusd->xbusd_path, "mac",
+ mac, sizeof(mac));
if (err) {
aprint_error_dev(self, "can't read mac address, err %d\n", err);
return;
}
- for (i = 0, p = val; i < 6; i++) {
+ for (i = 0, p = mac; i < ETHER_ADDR_LEN; i++) {
sc->sc_enaddr[i] = strtoul(p, &e, 16);
if ((e[0] == '\0' && i != 5) && e[0] != ':') {
aprint_error_dev(self,
- "%s is not a valid mac address\n", val);
- free(val, M_DEVBUF);
+ "%s is not a valid mac address\n", mac);
return;
}
p = &e[1];
}
- free(val, M_DEVBUF);
aprint_normal_dev(self, "MAC address %s\n",
ether_sprintf(sc->sc_enaddr));
diff -r c9b93a1031b2 -r ad5b96f00bc7 sys/arch/xen/xen/pciback.c
--- a/sys/arch/xen/xen/pciback.c Tue Apr 07 11:12:25 2020 +0000
+++ b/sys/arch/xen/xen/pciback.c Tue Apr 07 11:47:05 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pciback.c,v 1.20 2020/04/07 08:14:42 jdolecek Exp $ */
+/* $NetBSD: pciback.c,v 1.21 2020/04/07 11:47:06 jdolecek Exp $ */
/*
* Copyright (c) 2009 Manuel Bouyer.
@@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pciback.c,v 1.20 2020/04/07 08:14:42 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pciback.c,v 1.21 2020/04/07 11:47:06 jdolecek Exp $");
#include "opt_xen.h"
@@ -35,7 +35,6 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/errno.h>
-#include <sys/malloc.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/queue.h>
@@ -450,7 +449,6 @@
{
struct pb_xenbus_instance *pbxi;
long domid;
- char *val;
char path[10];
int i, err;
u_long num_devs;
@@ -493,15 +491,15 @@
goto fail;
}
for (i = 0; i < num_devs; i++) {
+ char dev[64];
snprintf(path, sizeof(path), "dev-%d", i);
if ((err = xenbus_read(NULL, xbusd->xbusd_path, path,
- NULL, &val)) != 0) {
+ dev, sizeof(dev))) != 0) {
aprint_error("pciback: can' read %s/%s: %d\n",
xbusd->xbusd_path, path, err);
goto fail;
}
- pciback_xenbus_export_device(pbxi, val);
- free(val, M_DEVBUF);
+ pciback_xenbus_export_device(pbxi, dev);
}
pciback_xenbus_export_roots(pbxi);
if ((err = xenbus_switch_state(xbusd, NULL, XenbusStateInitialised))) {
diff -r c9b93a1031b2 -r ad5b96f00bc7 sys/arch/xen/xen/shutdown_xenbus.c
--- a/sys/arch/xen/xen/shutdown_xenbus.c Tue Apr 07 11:12:25 2020 +0000
+++ b/sys/arch/xen/xen/shutdown_xenbus.c Tue Apr 07 11:47:05 2020 +0000
@@ -1,4 +1,4 @@
-/* $Id: shutdown_xenbus.c,v 1.7 2011/09/20 00:12:24 jym Exp $ */
+/* $Id: shutdown_xenbus.c,v 1.8 2020/04/07 11:47:06 jdolecek Exp $ */
/*-
* Copyright (c)2006 YAMAMOTO Takashi,
@@ -56,10 +56,9 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: shutdown_xenbus.c,v 1.7 2011/09/20 00:12:24 jym Exp $");
+__KERNEL_RCSID(0, "$NetBSD: shutdown_xenbus.c,v 1.8 2020/04/07 11:47:06 jdolecek Exp $");
#include <sys/param.h>
-#include <sys/malloc.h>
#include <dev/sysmon/sysmonvar.h>
@@ -89,8 +88,7 @@
struct xenbus_transaction *xbt;
int error;
- char *reqstr;
- unsigned int reqstrlen;
+ char reqstr[32];
again:
xbt = xenbus_transaction_start();
@@ -98,7 +96,7 @@
return;
}
error = xenbus_read(xbt, SHUTDOWN_PATH, SHUTDOWN_NAME,
- &reqstrlen, &reqstr);
+ reqstr, sizeof(reqstr));
if (error) {
if (error != ENOENT) {
printf("%s: xenbus_read %d\n", __func__, error);
@@ -110,14 +108,13 @@
}
return;
}
- KASSERT(strlen(reqstr) == reqstrlen);
+
error = xenbus_rm(xbt, SHUTDOWN_PATH, SHUTDOWN_NAME);
if (error) {
printf("%s: xenbus_rm %d\n", __func__, error);
}
error = xenbus_transaction_end(xbt, 0);
if (error == EAGAIN) {
- free(reqstr, M_DEVBUF);
goto again;
}
if (error != 0) {
@@ -135,7 +132,6 @@
} else {
printf("ignore shutdown request: %s\n", reqstr);
}
- free(reqstr, M_DEVBUF);
}
static struct xenbus_watch xenbus_shutdown_watch = {
diff -r c9b93a1031b2 -r ad5b96f00bc7 sys/arch/xen/xen/xbd_xenbus.c
--- a/sys/arch/xen/xen/xbd_xenbus.c Tue Apr 07 11:12:25 2020 +0000
+++ b/sys/arch/xen/xen/xbd_xenbus.c Tue Apr 07 11:47:05 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: xbd_xenbus.c,v 1.96 2020/03/13 00:32:05 jdolecek Exp $ */
+/* $NetBSD: xbd_xenbus.c,v 1.97 2020/04/07 11:47:06 jdolecek Exp $ */
/*
* Copyright (c) 2006 Manuel Bouyer.
@@ -50,7 +50,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.96 2020/03/13 00:32:05 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.97 2020/04/07 11:47:06 jdolecek Exp $");
#include "opt_xen.h"
@@ -261,28 +261,6 @@
dk_init(&sc->sc_dksc, self, DKTYPE_ESDI);
disk_init(&sc->sc_dksc.sc_dkdev, device_xname(self), &xbddkdriver);
-#ifdef XBD_DEBUG
- printf("path: %s\n", xa->xa_xbusd->xbusd_path);
- snprintf(id_str, sizeof(id_str), "%d", xa->xa_id);
- err = xenbus_directory(NULL, "device/vbd", id_str, &dir_n, &dir);
- if (err) {
- aprint_error_dev(self, "xenbus_directory err %d\n", err);
- } else {
- printf("%s/\n", xa->xa_xbusd->xbusd_path);
- for (i = 0; i < dir_n; i++) {
- printf("\t/%s", dir[i]);
- err = xenbus_read(NULL, xa->xa_xbusd->xbusd_path,
- dir[i], NULL, &val);
- if (err) {
- aprint_error_dev(self, "xenbus_read err %d\n",
- err);
- } else {
- printf(" = %s\n", val);
- free(val, M_DEVBUF);
- }
- }
- }
-#endif /* XBD_DEBUG */
sc->sc_xbusd = xa->xa_xbusd;
sc->sc_xbusd->xbusd_otherend_changed = xbd_backend_changed;
Home |
Main Index |
Thread Index |
Old Index