mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-25 03:37:45 +03:00
OpenZFS 7431 - ZFS Channel Programs
Authored by: Chris Williamson <chris.williamson@delphix.com> Reviewed by: Matthew Ahrens <mahrens@delphix.com> Reviewed by: George Wilson <george.wilson@delphix.com> Reviewed by: John Kennedy <john.kennedy@delphix.com> Reviewed by: Dan Kimmel <dan.kimmel@delphix.com> Approved by: Garrett D'Amore <garrett@damore.org> Ported-by: Don Brady <don.brady@delphix.com> Ported-by: John Kennedy <john.kennedy@delphix.com> OpenZFS-issue: https://www.illumos.org/issues/7431 OpenZFS-commit: https://github.com/openzfs/openzfs/commit/dfc11533 Porting Notes: * The CLI long option arguments for '-t' and '-m' don't parse on linux * Switched from kmem_alloc to vmem_alloc in zcp_lua_alloc * Lua implementation is built as its own module (zlua.ko) * Lua headers consumed directly by zfs code moved to 'include/sys/lua/' * There is no native setjmp/longjump available in stock Linux kernel. Brought over implementations from illumos and FreeBSD * The get_temporary_prop() was adapted due to VFS platform differences * Use of inline functions in lua parser to reduce stack usage per C call * Skip some ZFS Test Suite ZCP tests on sparc64 to avoid stack overflow
This commit is contained in:
committed by
Brian Behlendorf
parent
8824a7f133
commit
d99a015343
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright (c) 2016 by Delphix. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <sys/lua/lua.h>
|
||||
|
||||
|
||||
ssize_t
|
||||
lcompat_sprintf(char *buf, const char *fmt, ...)
|
||||
{
|
||||
ssize_t res;
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
res = vsnprintf(buf, INT_MAX, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
return (res);
|
||||
}
|
||||
|
||||
int64_t
|
||||
lcompat_strtoll(const char *str, char **ptr)
|
||||
{
|
||||
int base;
|
||||
const char *cp;
|
||||
int digits;
|
||||
int64_t value;
|
||||
boolean_t is_negative;
|
||||
|
||||
cp = str;
|
||||
while (*cp == ' ' || *cp == '\t' || *cp == '\n') {
|
||||
cp++;
|
||||
}
|
||||
is_negative = (*cp == '-');
|
||||
if (is_negative) {
|
||||
cp++;
|
||||
}
|
||||
base = 10;
|
||||
|
||||
if (*cp == '0') {
|
||||
base = 8;
|
||||
cp++;
|
||||
if (*cp == 'x' || *cp == 'X') {
|
||||
base = 16;
|
||||
cp++;
|
||||
}
|
||||
}
|
||||
|
||||
value = 0;
|
||||
for (; *cp != '\0'; cp++) {
|
||||
if (*cp >= '0' && *cp <= '9') {
|
||||
digits = *cp - '0';
|
||||
} else if (*cp >= 'a' && *cp <= 'f') {
|
||||
digits = *cp - 'a' + 10;
|
||||
} else if (*cp >= 'A' && *cp <= 'F') {
|
||||
digits = *cp - 'A' + 10;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
if (digits >= base) {
|
||||
break;
|
||||
}
|
||||
value = (value * base) + digits;
|
||||
}
|
||||
|
||||
if (ptr != NULL) {
|
||||
*ptr = (char *)cp;
|
||||
}
|
||||
if (is_negative) {
|
||||
value = -value;
|
||||
}
|
||||
return (value);
|
||||
}
|
||||
|
||||
int64_t
|
||||
lcompat_pow(int64_t x, int64_t y)
|
||||
{
|
||||
int64_t result = 1;
|
||||
if (y < 0)
|
||||
return (0);
|
||||
|
||||
while (y) {
|
||||
if (y & 1)
|
||||
result *= x;
|
||||
y >>= 1;
|
||||
x *= x;
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
|
||||
int
|
||||
lcompat_hashnum(int64_t x)
|
||||
{
|
||||
x = (~x) + (x << 18);
|
||||
x = x ^ (x >> 31);
|
||||
x = x * 21;
|
||||
x = x ^ (x >> 11);
|
||||
x = x + (x << 6);
|
||||
x = x ^ (x >> 22);
|
||||
return ((int)x);
|
||||
}
|
||||
Reference in New Issue
Block a user