Reduce stack usage by vn_open()
We should not put a 4k maxpathlen buffer on the stack, instead locate it to the heap. Even in user space we run ztest with 8K
This commit is contained in:
parent
428870ff73
commit
edbb93c11d
|
@ -0,0 +1,8 @@
|
|||
From: Brian Behlendorf <behlendorf1@llnl.gov>
|
||||
Subject: [PATCH] fix stack vn_open
|
||||
|
||||
We should not put a 4k maxpathlen buffer on the stack, instead
|
||||
locate it to the heap. Even in user space we run ztest with 8K
|
||||
stacks to verify correctness
|
||||
|
||||
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
|
|
@ -327,9 +327,11 @@ vn_open(char *path, int x1, int flags, int mode, vnode_t **vpp, int x2, int x3)
|
|||
int fd;
|
||||
vnode_t *vp;
|
||||
int old_umask;
|
||||
char realpath[MAXPATHLEN];
|
||||
char *realpath;
|
||||
struct stat64 st;
|
||||
|
||||
realpath = umem_alloc(MAXPATHLEN, UMEM_NOFAIL);
|
||||
|
||||
/*
|
||||
* If we're accessing a real disk from userland, we need to use
|
||||
* the character interface to avoid caching. This is particularly
|
||||
|
@ -343,11 +345,16 @@ vn_open(char *path, int x1, int flags, int mode, vnode_t **vpp, int x2, int x3)
|
|||
if (strncmp(path, "/dev/", 5) == 0) {
|
||||
char *dsk;
|
||||
fd = open64(path, O_RDONLY);
|
||||
if (fd == -1)
|
||||
return (errno);
|
||||
if (fd == -1) {
|
||||
err = errno;
|
||||
free(realpath);
|
||||
return (err);
|
||||
}
|
||||
if (fstat64(fd, &st) == -1) {
|
||||
err = errno;
|
||||
close(fd);
|
||||
return (errno);
|
||||
free(realpath);
|
||||
return (err);
|
||||
}
|
||||
close(fd);
|
||||
(void) sprintf(realpath, "%s", path);
|
||||
|
@ -357,8 +364,11 @@ vn_open(char *path, int x1, int flags, int mode, vnode_t **vpp, int x2, int x3)
|
|||
dsk + 1);
|
||||
} else {
|
||||
(void) sprintf(realpath, "%s", path);
|
||||
if (!(flags & FCREAT) && stat64(realpath, &st) == -1)
|
||||
return (errno);
|
||||
if (!(flags & FCREAT) && stat64(realpath, &st) == -1) {
|
||||
err = errno;
|
||||
free(realpath);
|
||||
return (err);
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & FCREAT)
|
||||
|
@ -369,6 +379,7 @@ vn_open(char *path, int x1, int flags, int mode, vnode_t **vpp, int x2, int x3)
|
|||
* FREAD and FWRITE to the corresponding O_RDONLY, O_WRONLY, and O_RDWR.
|
||||
*/
|
||||
fd = open64(realpath, flags - FREAD, mode);
|
||||
free(realpath);
|
||||
|
||||
if (flags & FCREAT)
|
||||
(void) umask(old_umask);
|
||||
|
|
Loading…
Reference in New Issue