mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 18:40:43 +03:00
OpenZFS restructuring - libspl
Factor Linux specific pieces out of libspl. Reviewed-by: Ryan Moeller <ryan@ixsystems.com> Reviewed-by: Sean Eric Fagan <sef@ixsystems.com> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Matt Macy <mmacy@FreeBSD.org> Closes #9336
This commit is contained in:
committed by
Brian Behlendorf
parent
6360e2779e
commit
d31277abb1
+6
-54
@@ -504,60 +504,16 @@ vn_open(char *path, int x1, int flags, int mode, vnode_t **vpp, int x2, int x3)
|
||||
int dump_fd = -1;
|
||||
vnode_t *vp;
|
||||
int old_umask = 0;
|
||||
char *realpath;
|
||||
struct stat64 st;
|
||||
int err;
|
||||
|
||||
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
|
||||
* important if we're trying to look at a real in-kernel storage
|
||||
* pool from userland, e.g. via zdb, because otherwise we won't
|
||||
* see the changes occurring under the segmap cache.
|
||||
* On the other hand, the stupid character device returns zero
|
||||
* for its size. So -- gag -- we open the block device to get
|
||||
* its size, and remember it for subsequent VOP_GETATTR().
|
||||
*/
|
||||
#if defined(__sun__) || defined(__sun)
|
||||
if (strncmp(path, "/dev/", 5) == 0) {
|
||||
#else
|
||||
if (0) {
|
||||
#endif
|
||||
char *dsk;
|
||||
fd = open64(path, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
err = errno;
|
||||
free(realpath);
|
||||
return (err);
|
||||
}
|
||||
if (fstat64(fd, &st) == -1) {
|
||||
err = errno;
|
||||
close(fd);
|
||||
free(realpath);
|
||||
return (err);
|
||||
}
|
||||
close(fd);
|
||||
(void) sprintf(realpath, "%s", path);
|
||||
dsk = strstr(path, "/dsk/");
|
||||
if (dsk != NULL)
|
||||
(void) sprintf(realpath + (dsk - path) + 1, "r%s",
|
||||
dsk + 1);
|
||||
} else {
|
||||
(void) sprintf(realpath, "%s", path);
|
||||
if (!(flags & FCREAT) && stat64(realpath, &st) == -1) {
|
||||
err = errno;
|
||||
free(realpath);
|
||||
return (err);
|
||||
}
|
||||
if (!(flags & FCREAT) && stat64(path, &st) == -1) {
|
||||
err = errno;
|
||||
return (err);
|
||||
}
|
||||
|
||||
if (!(flags & FCREAT) && S_ISBLK(st.st_mode)) {
|
||||
#ifdef __linux__
|
||||
if (!(flags & FCREAT) && S_ISBLK(st.st_mode))
|
||||
flags |= O_DIRECT;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (flags & FCREAT)
|
||||
old_umask = umask(0);
|
||||
@@ -566,10 +522,9 @@ vn_open(char *path, int x1, int flags, int mode, vnode_t **vpp, int x2, int x3)
|
||||
* The construct 'flags - FREAD' conveniently maps combinations of
|
||||
* FREAD and FWRITE to the corresponding O_RDONLY, O_WRONLY, and O_RDWR.
|
||||
*/
|
||||
fd = open64(realpath, flags - FREAD, mode);
|
||||
fd = open64(path, flags - FREAD, mode);
|
||||
if (fd == -1) {
|
||||
err = errno;
|
||||
free(realpath);
|
||||
return (err);
|
||||
}
|
||||
|
||||
@@ -579,12 +534,11 @@ vn_open(char *path, int x1, int flags, int mode, vnode_t **vpp, int x2, int x3)
|
||||
if (vn_dumpdir != NULL) {
|
||||
char *dumppath = umem_zalloc(MAXPATHLEN, UMEM_NOFAIL);
|
||||
(void) snprintf(dumppath, MAXPATHLEN,
|
||||
"%s/%s", vn_dumpdir, basename(realpath));
|
||||
"%s/%s", vn_dumpdir, basename(path));
|
||||
dump_fd = open64(dumppath, O_CREAT | O_WRONLY, 0666);
|
||||
umem_free(dumppath, MAXPATHLEN);
|
||||
if (dump_fd == -1) {
|
||||
err = errno;
|
||||
free(realpath);
|
||||
close(fd);
|
||||
return (err);
|
||||
}
|
||||
@@ -592,8 +546,6 @@ vn_open(char *path, int x1, int flags, int mode, vnode_t **vpp, int x2, int x3)
|
||||
dump_fd = -1;
|
||||
}
|
||||
|
||||
free(realpath);
|
||||
|
||||
if (fstat64_blk(fd, &st) == -1) {
|
||||
err = errno;
|
||||
close(fd);
|
||||
|
||||
Reference in New Issue
Block a user