summaryrefslogtreecommitdiffstats
path: root/sys/kern
diff options
context:
space:
mode:
authorscottl <scottl@FreeBSD.org>2014-01-07 01:51:48 +0000
committerscottl <scottl@FreeBSD.org>2014-01-07 01:51:48 +0000
commitcd4455d63815797dee4bd5d2fbe903ace2888a8f (patch)
treee4a932aed55b2e611c4a7cbe18560be7eb0cd1f1 /sys/kern
parent0a34594b9cd7c8b87f719ed058da6be2b756a8e5 (diff)
downloadFreeBSD-src-cd4455d63815797dee4bd5d2fbe903ace2888a8f.zip
FreeBSD-src-cd4455d63815797dee4bd5d2fbe903ace2888a8f.tar.gz
MFC Alexander Motin's direct dispatch, multi-queue, and finer-grained
locking support for CAM r256826: Fix several target mode SIMs to not blindly clear ccb_h.flags field of ATIO CCBs. Not all CCB flags there belong to them. r256836: Remove hard limit on number of BIOs handled with one ATA TRIM request. r256843: Merge CAM locking changes from the projects/camlock branch to radically reduce lock congestion and improve SMP scalability of the SCSI/ATA stack, preparing the ground for the coming next GEOM direct dispatch support. r256888: Unconditionally acquire periph reference on CCB allocation failure. r256895: Fix memory and references leak due to unfreed path. r256960: Move CAM_UNQUEUED_INDEX setting to the last moment and under the periph lock. This fixes race condition with cam_periph_ccbwait(), causing use-after-free. r256975: Minor (mostly cosmetical) addition to r256960. r257054: Some microoptimizations for da and ada drivers: - Replace ordered_tag_count counter with single flag; - From da remove outstanding_cmds counter, duplicating pending_ccbs list; - From da_softc remove unused links field. r257482: Fix lock recursion, triggered by `smartctl -a /dev/adaX`. r257501: Make getenv_*() functions and respectively TUNABLE_*_FETCH() macros not allocate memory and so not require sleepable environment. getenv() has already used on-stack temporary storage, so just use it more rationally. getenv_string() receives buffer as argument, so don't need another one. r257914: Some CAM locks polishing: - Fix LOR and possible lock recursion when handling high-power commands. Introduce new lock to protect left power quota and list of frozen devices. - Correct locking around xpt periph creation. - Remove seems never used XPT_FLAG_OPEN xpt periph flag. Again, Netflix assisted with testing the merge, but all of the credit goes to Alexander and iX Systems. Submitted by: mav Sponsored by: iX Systems
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/kern_environment.c46
1 files changed, 19 insertions, 27 deletions
diff --git a/sys/kern/kern_environment.c b/sys/kern/kern_environment.c
index e89b3f7..ff453cb 100644
--- a/sys/kern/kern_environment.c
+++ b/sys/kern/kern_environment.c
@@ -315,20 +315,12 @@ char *
getenv(const char *name)
{
char buf[KENV_MNAMELEN + 1 + KENV_MVALLEN + 1];
- char *ret, *cp;
- int len;
+ char *ret;
if (dynamic_kenv) {
- mtx_lock(&kenv_lock);
- cp = _getenv_dynamic(name, NULL);
- if (cp != NULL) {
- strcpy(buf, cp);
- mtx_unlock(&kenv_lock);
- len = strlen(buf) + 1;
- ret = malloc(len, M_KENV, M_WAITOK);
- strcpy(ret, buf);
+ if (getenv_string(name, buf, sizeof(buf))) {
+ ret = strdup(buf, M_KENV);
} else {
- mtx_unlock(&kenv_lock);
ret = NULL;
WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
"getenv");
@@ -458,15 +450,20 @@ unsetenv(const char *name)
int
getenv_string(const char *name, char *data, int size)
{
- char *tmp;
+ char *cp;
- tmp = getenv(name);
- if (tmp != NULL) {
- strlcpy(data, tmp, size);
- freeenv(tmp);
- return (1);
- } else
- return (0);
+ if (dynamic_kenv) {
+ mtx_lock(&kenv_lock);
+ cp = _getenv_dynamic(name, NULL);
+ if (cp != NULL)
+ strlcpy(data, cp, size);
+ mtx_unlock(&kenv_lock);
+ } else {
+ cp = _getenv_static(name);
+ if (cp != NULL)
+ strlcpy(data, cp, size);
+ }
+ return (cp != NULL);
}
/*
@@ -535,18 +532,15 @@ getenv_ulong(const char *name, unsigned long *data)
int
getenv_quad(const char *name, quad_t *data)
{
- char *value;
+ char value[KENV_MNAMELEN + 1 + KENV_MVALLEN + 1];
char *vtp;
quad_t iv;
- value = getenv(name);
- if (value == NULL)
+ if (!getenv_string(name, value, sizeof(value)))
return (0);
iv = strtoq(value, &vtp, 0);
- if (vtp == value || (vtp[0] != '\0' && vtp[1] != '\0')) {
- freeenv(value);
+ if (vtp == value || (vtp[0] != '\0' && vtp[1] != '\0'))
return (0);
- }
switch (vtp[0]) {
case 't': case 'T':
iv *= 1024;
@@ -559,11 +553,9 @@ getenv_quad(const char *name, quad_t *data)
case '\0':
break;
default:
- freeenv(value);
return (0);
}
*data = iv;
- freeenv(value);
return (1);
}
OpenPOWER on IntegriCloud