summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan McDonald <danmcd@joyent.com>2021-11-03 10:25:18 -0400
committerDan McDonald <danmcd@joyent.com>2021-11-03 10:25:18 -0400
commit6aa2048ab726a6fa7d29dc204e77b1d6ee48eb2e (patch)
treec85ff71e6bf0d418b19243d43604ba9a1f31ff84
parent1e09a794d96ea9140ef8ebc9ed4e214d4344d83a (diff)
parent6e2462f93bf3de7b08885a4677464e11be3c807b (diff)
downloadillumos-joyent-6aa2048ab726a6fa7d29dc204e77b1d6ee48eb2e.tar.gz
[illumos-gate merge]
commit 6e2462f93bf3de7b08885a4677464e11be3c807b 14196 Want librename commit 99e6398ed34e1943640f382fec1971ba1ecc2f99 14036 pxeboot: improve and simplify rx handling Conflicts: usr/src/lib/Makefile usr/src/lib/librename/Makefile usr/src/lib/librename/Makefile.com usr/src/lib/librename/amd64/Makefile usr/src/lib/librename/common/librename.c usr/src/lib/librename/common/librename.h usr/src/lib/librename/i386/Makefile
-rw-r--r--exception_lists/packaging6
-rw-r--r--usr/src/boot/sys/boot/i386/libi386/pxe.c148
-rw-r--r--usr/src/lib/librename/Makefile7
-rw-r--r--usr/src/lib/librename/Makefile.com6
-rw-r--r--usr/src/lib/librename/amd64/Makefile2
-rw-r--r--usr/src/lib/librename/common/librename.c32
-rw-r--r--usr/src/lib/librename/i386/Makefile2
-rw-r--r--usr/src/pkg/manifests/system-library.mf2
8 files changed, 136 insertions, 69 deletions
diff --git a/exception_lists/packaging b/exception_lists/packaging
index 85a4eb70a6..39cbf245a5 100644
--- a/exception_lists/packaging
+++ b/exception_lists/packaging
@@ -385,6 +385,12 @@ usr/lib/libcmdutils.so
usr/lib/amd64/libcmdutils.so i386
usr/lib/sparcv9/libcmdutils.so sparc
#
+# Private librename
+#
+usr/lib/librename.so
+usr/lib/amd64/librename.so i386
+usr/include/librename.h
+#
# Private interfaces in libsec
#
usr/include/aclutils.h
diff --git a/usr/src/boot/sys/boot/i386/libi386/pxe.c b/usr/src/boot/sys/boot/i386/libi386/pxe.c
index 8ebd0c9f08..49585891bd 100644
--- a/usr/src/boot/sys/boot/i386/libi386/pxe.c
+++ b/usr/src/boot/sys/boot/i386/libi386/pxe.c
@@ -29,6 +29,8 @@
#include <sys/cdefs.h>
#include <stand.h>
+#include <errno.h>
+#include <stdbool.h>
#include <stddef.h>
#include <string.h>
#include <stdarg.h>
@@ -441,77 +443,144 @@ pxe_netif_init(struct iodesc *desc, void *machdep_hint __unused)
}
static int
-pxe_netif_receive(void **pkt)
+pxe_netif_receive_isr(t_PXENV_UNDI_ISR *isr, void **pkt, ssize_t *retsize)
{
- t_PXENV_UNDI_ISR *isr;
+ static bool data_pending;
char *buf, *ptr, *frame;
size_t size, rsize;
- isr = bio_alloc(sizeof (*isr));
- if (isr == NULL)
- return (-1);
+ buf = NULL;
+ size = rsize = 0;
+
+ /*
+ * We can save ourselves the next two pxe calls because we already know
+ * we weren't done grabbing everything.
+ */
+ if (data_pending) {
+ data_pending = false;
+ goto nextbuf;
+ }
+ /*
+ * We explicitly don't check for OURS/NOT_OURS as a result of START;
+ * it's been reported that some cards are known to mishandle these.
+ */
bzero(isr, sizeof (*isr));
isr->FuncFlag = PXENV_UNDI_ISR_IN_START;
pxe_call(PXENV_UNDI_ISR, isr);
+ /* We could translate Status... */
if (isr->Status != 0) {
- bio_free(isr, sizeof (*isr));
- return (-1);
+ return (ENXIO);
}
bzero(isr, sizeof (*isr));
isr->FuncFlag = PXENV_UNDI_ISR_IN_PROCESS;
pxe_call(PXENV_UNDI_ISR, isr);
if (isr->Status != 0) {
- bio_free(isr, sizeof (*isr));
- return (-1);
+ return (ENXIO);
}
-
- while (isr->FuncFlag != PXENV_UNDI_ISR_OUT_RECEIVE) {
- if (isr->Status != 0 ||
- isr->FuncFlag == PXENV_UNDI_ISR_OUT_DONE) {
- bio_free(isr, sizeof (*isr));
- return (-1);
- }
- bzero(isr, sizeof (*isr));
- isr->FuncFlag = PXENV_UNDI_ISR_IN_GET_NEXT;
- pxe_call(PXENV_UNDI_ISR, isr);
+ if (isr->FuncFlag == PXENV_UNDI_ISR_OUT_BUSY) {
+ /*
+ * Let the caller decide if we need to be restarted. It will
+ * currently blindly restart us, but it could check timeout in
+ * the future.
+ */
+ return (ERESTART);
}
- size = isr->FrameLength;
- buf = malloc(size + ETHER_ALIGN);
- if (buf == NULL) {
- bio_free(isr, sizeof (*isr));
- return (-1);
- }
- ptr = buf + ETHER_ALIGN;
- rsize = 0;
+ /*
+ * By design, we'll hardly ever hit this terminal condition unless we
+ * pick up nothing but tx interrupts here. More frequently, we will
+ * process rx buffers until we hit the terminal condition in the middle.
+ */
+ while (isr->FuncFlag != PXENV_UNDI_ISR_OUT_DONE) {
+ /*
+ * This might have given us PXENV_UNDI_ISR_OUT_TRANSMIT, in
+ * which case we can just disregard and move on to the next
+ * buffer/frame.
+ */
+ if (isr->FuncFlag != PXENV_UNDI_ISR_OUT_RECEIVE)
+ goto nextbuf;
+
+ if (buf == NULL) {
+ /*
+ * Grab size from the first Frame that we picked up,
+ * allocate an rx buf to hold. Careful here, as we may
+ * see a fragmented frame that's spread out across
+ * multiple GET_NEXT calls.
+ */
+ size = isr->FrameLength;
+ buf = malloc(size + ETHER_ALIGN);
+ if (buf == NULL)
+ return (ENOMEM);
+
+ ptr = buf + ETHER_ALIGN;
+ }
- while (rsize < size) {
frame = (char *)((uintptr_t)isr->Frame.segment << 4);
frame += isr->Frame.offset;
bcopy(PTOV(frame), ptr, isr->BufferLength);
ptr += isr->BufferLength;
rsize += isr->BufferLength;
+ /*
+ * Stop here before we risk catching the start of another frame.
+ * It would be nice to continue reading until we actually get a
+ * PXENV_UNDI_ISR_OUT_DONE, but our network stack in libsa isn't
+ * suitable for reading more than one packet at a time.
+ */
+ if (rsize >= size) {
+ data_pending = true;
+ break;
+ }
+
+nextbuf:
bzero(isr, sizeof (*isr));
isr->FuncFlag = PXENV_UNDI_ISR_IN_GET_NEXT;
pxe_call(PXENV_UNDI_ISR, isr);
if (isr->Status != 0) {
- bio_free(isr, sizeof (*isr));
free(buf);
- return (-1);
+ return (ENXIO);
}
+ }
- /* Did we got another update? */
- if (isr->FuncFlag == PXENV_UNDI_ISR_OUT_RECEIVE)
- continue;
- break;
+ /*
+ * We may have never picked up a frame at all (all tx), in which case
+ * the caller should restart us.
+ */
+ if (rsize == 0) {
+ return (ERESTART);
}
*pkt = buf;
+ *retsize = rsize;
+ return (0);
+}
+
+static int
+pxe_netif_receive(void **pkt, ssize_t *size)
+{
+ t_PXENV_UNDI_ISR *isr;
+ int ret;
+
+ isr = bio_alloc(sizeof (*isr));
+ if (isr == NULL)
+ return (ENOMEM);
+
+ /*
+ * This completely ignores the timeout specified in pxe_netif_get(), but
+ * we shouldn't be running long enough here for that to make a
+ * difference.
+ */
+ for (;;) {
+ /* We'll only really re-enter for PXENV_UNDI_ISR_OUT_BUSY. */
+ ret = pxe_netif_receive_isr(isr, pkt, size);
+ if (ret != ERESTART)
+ break;
+ }
+
bio_free(isr, sizeof (*isr));
- return (rsize);
+ return (ret);
}
static ssize_t
@@ -519,17 +588,20 @@ pxe_netif_get(struct iodesc *desc __unused, void **pkt, time_t timeout)
{
time_t t;
void *ptr;
- ssize_t ret = -1;
+ int ret = -1;
+ ssize_t size;
t = getsecs();
+ size = 0;
while ((getsecs() - t) < timeout) {
- ret = pxe_netif_receive(&ptr);
+ ret = pxe_netif_receive(&ptr, &size);
if (ret != -1) {
*pkt = ptr;
break;
}
}
- return (ret);
+
+ return (ret == 0 ? size : -1);
}
static ssize_t
diff --git a/usr/src/lib/librename/Makefile b/usr/src/lib/librename/Makefile
index 1278c6cc9d..6ae7851aa3 100644
--- a/usr/src/lib/librename/Makefile
+++ b/usr/src/lib/librename/Makefile
@@ -24,15 +24,14 @@ all := TARGET = all
clean := TARGET = clean
clobber := TARGET = clobber
install := TARGET = install
-lint := TARGET = lint
.KEEP_STATE:
-all clean clobber lint: $(SUBDIRS)
+all clean clobber: $(SUBDIRS)
-install: $(SUBDIRS) install_h
+install: $(SUBDIRS) install_h
-install_h: $(ROOTHDRS)
+install_h: $(ROOTHDRS)
check: $(CHECKHDRS)
diff --git a/usr/src/lib/librename/Makefile.com b/usr/src/lib/librename/Makefile.com
index f0a22f25ac..ab09db7efb 100644
--- a/usr/src/lib/librename/Makefile.com
+++ b/usr/src/lib/librename/Makefile.com
@@ -15,11 +15,11 @@
LIBRARY = librename.a
VERS = .1
-OBJECTS = librename.o \
+OBJECTS = librename.o
include ../../Makefile.lib
-LIBS = $(DYNLIB) $(LINTLIB)
+LIBS = $(DYNLIB)
LDLIBS += -lc
CPPFLAGS += -I../common
@@ -29,6 +29,4 @@ SRCDIR = ../common
all: $(LIBS)
-lint: lintcheck
-
include ../../Makefile.targ
diff --git a/usr/src/lib/librename/amd64/Makefile b/usr/src/lib/librename/amd64/Makefile
index 15d904c616..e03ee6aac6 100644
--- a/usr/src/lib/librename/amd64/Makefile
+++ b/usr/src/lib/librename/amd64/Makefile
@@ -16,4 +16,4 @@
include ../Makefile.com
include ../../Makefile.lib.64
-install: all $(ROOTLIBS64) $(ROOTLINKS64) $(ROOTLINT64)
+install: all $(ROOTLIBS64) $(ROOTLINKS64)
diff --git a/usr/src/lib/librename/common/librename.c b/usr/src/lib/librename/common/librename.c
index 1e198a50a3..1f522dcec3 100644
--- a/usr/src/lib/librename/common/librename.c
+++ b/usr/src/lib/librename/common/librename.c
@@ -23,6 +23,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
+#include <sys/debug.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@@ -89,12 +90,10 @@ librename_atomic_fdinit(int fd, const char *file, const char *prefix,
return (ret);
}
-
lrap->lra_fname = strdup(file);
if (lrap->lra_fname == NULL) {
ret = errno;
- if (close(lrap->lra_dirfd) != 0)
- abort();
+ VERIFY0(close(lrap->lra_dirfd));
free(lrap);
return (ret);
}
@@ -108,8 +107,7 @@ librename_atomic_fdinit(int fd, const char *file, const char *prefix,
if (ret == -1) {
ret = errno;
free(lrap->lra_fname);
- if (close(lrap->lra_dirfd) != 0)
- abort();
+ VERIFY0(close(lrap->lra_dirfd));
free(lrap);
return (errno);
}
@@ -127,14 +125,12 @@ librename_atomic_fdinit(int fd, const char *file, const char *prefix,
ret = errno;
free(lrap->lra_altname);
free(lrap->lra_fname);
- if (close(lrap->lra_dirfd) != 0)
- abort();
+ VERIFY0(close(lrap->lra_dirfd));
free(lrap);
return (ret);
}
- if (mutex_init(&lrap->lra_lock, USYNC_THREAD, NULL) != 0)
- abort();
+ VERIFY0(mutex_init(&lrap->lra_lock, USYNC_THREAD, NULL));
lrap->lra_state = LIBRENAME_ATOMIC_INITIAL;
*outp = lrap;
@@ -151,8 +147,7 @@ librename_atomic_init(const char *dir, const char *file, const char *prefix,
return (errno);
ret = librename_atomic_fdinit(fd, file, prefix, mode, flags, outp);
- if (close(fd) != 0)
- abort();
+ VERIFY0(close(fd));
return (ret);
}
@@ -175,8 +170,7 @@ librename_atomic_commit(librename_atomic_t *lrap)
{
int ret = 0;
- if (mutex_lock(&lrap->lra_lock) != 0)
- abort();
+ VERIFY0(mutex_lock(&lrap->lra_lock));
if (lrap->lra_state == LIBRENAME_ATOMIC_COMPLETED) {
ret = EINVAL;
goto out;
@@ -208,8 +202,7 @@ librename_atomic_commit(librename_atomic_t *lrap)
lrap->lra_state = LIBRENAME_ATOMIC_COMPLETED;
out:
- if (mutex_unlock(&lrap->lra_lock) != 0)
- abort();
+ VERIFY0(mutex_unlock(&lrap->lra_lock));
return (ret);
}
@@ -219,11 +212,8 @@ librename_atomic_fini(librename_atomic_t *lrap)
free(lrap->lra_altname);
free(lrap->lra_fname);
- if (close(lrap->lra_tmpfd) != 0)
- abort();
- if (close(lrap->lra_dirfd) != 0)
- abort();
- if (mutex_destroy(&lrap->lra_lock) != 0)
- abort();
+ VERIFY0(close(lrap->lra_tmpfd));
+ VERIFY0(close(lrap->lra_dirfd));
+ VERIFY0(mutex_destroy(&lrap->lra_lock));
free(lrap);
}
diff --git a/usr/src/lib/librename/i386/Makefile b/usr/src/lib/librename/i386/Makefile
index 41e699e8f8..73fc6a2070 100644
--- a/usr/src/lib/librename/i386/Makefile
+++ b/usr/src/lib/librename/i386/Makefile
@@ -15,4 +15,4 @@
include ../Makefile.com
-install: all $(ROOTLIBS) $(ROOTLINKS) $(ROOTLINT)
+install: all $(ROOTLIBS) $(ROOTLINKS)
diff --git a/usr/src/pkg/manifests/system-library.mf b/usr/src/pkg/manifests/system-library.mf
index f5a0640ecf..d7abc4228b 100644
--- a/usr/src/pkg/manifests/system-library.mf
+++ b/usr/src/pkg/manifests/system-library.mf
@@ -378,6 +378,7 @@ file path=usr/lib/$(ARCH64)/libpcidb.so.1
file path=usr/lib/$(ARCH64)/libpkcs11.so.1
file path=usr/lib/$(ARCH64)/libproject.so.1
file path=usr/lib/$(ARCH64)/libraidcfg.so.1
+file path=usr/lib/$(ARCH64)/librename.so.1
file path=usr/lib/$(ARCH64)/libreparse.so.1
$(i386_ONLY)file path=usr/lib/$(ARCH64)/libsaveargs.so.1
file path=usr/lib/$(ARCH64)/libsched.so.1
@@ -451,6 +452,7 @@ file path=usr/lib/libpcidb.so.1
file path=usr/lib/libpkcs11.so.1
file path=usr/lib/libproject.so.1
file path=usr/lib/libraidcfg.so.1
+file path=usr/lib/librename.so.1
file path=usr/lib/libreparse.so.1
file path=usr/lib/libsched.so.1
file path=usr/lib/libsctp.so.1