int zfsslash2_init(void) { struct pscfs_args args = PSCFS_ARGS_INIT(0, NULL); extern struct fuse_lowlevel_ops pscfs_fuse_ops; extern struct fuse_session *fuse_session; extern struct pollfd pflfs_fds[]; extern int newfs_fd[2], pflfs_nfds; extern char *fuse_mount_options; int rc; if (pfl_systemf("umount %s", _PATH_KSTAT) == -1) psclog_warn("umount %s", _PATH_KSTAT); if (pipe(newfs_fd) == -1) psc_fatal("pipe"); pflfs_fds[0].fd = newfs_fd[0]; pflfs_fds[0].events = POLLIN; pflfs_nfds = 1; fuse_session = fuse_lowlevel_new(&args.pfa_av, &pscfs_fuse_ops, sizeof(pscfs_fuse_ops), NULL); pscthr_init(SLMTHRT_ZFS_KSTAT, slmzfskstatmthr_main, 0, "slmzfskstatmthr"); fuse_mount_options = ""; rc = libzfs_init_fusesocket(); if (rc == 0) rc = libzfs_init(); atexit(slm_unmount_kstat); return (rc); }
int pfl_odt_new(struct pfl_odt *t, const char *fn, int overwrite) { struct pfl_odt_hdr *h; h = t->odt_hdr; t->odt_fd = open(fn, O_CREAT | O_RDWR | (overwrite ? O_TRUNC : O_EXCL), 0600); if (t->odt_fd == -1) { psclog_warn("open %s", fn); return (-1); } if (pwrite(t->odt_fd, h, sizeof(*h), 0) != sizeof(*h)) { psclog_warn("write %s", fn); return (-1); } return (0); }
void slm_unmount_kstat(void) { char buf[BUFSIZ]; int rc; rc = snprintf(buf, sizeof(buf), "umount %s", _PATH_KSTAT); if (rc == -1) psc_fatal("snprintf: umount %s", _PATH_KSTAT); if (rc >= (int)sizeof(buf)) psc_fatalx("snprintf: umount %s: too long", _PATH_KSTAT); if (system(buf) == -1) psclog_warn("system(%s)", buf); }
void unmount(const char *mp) { char buf[BUFSIZ]; int rc; /* XXX do not let this hang */ rc = snprintf(buf, sizeof(buf), "umount '%s' || umount -f '%s' || umount -l '%s'", mp, mp, mp); if (rc == -1) psc_fatal("snprintf: umount %s", mp); if ((size_t)rc >= sizeof(buf)) psc_fatalx("snprintf: umount %s: too long", mp); if (system(buf) == -1) psclog_warn("system(%s)", buf); }
/* when copying local-to-local, make sure to cut estimate by half */ int pfl_getnfreecores(int want) { int nstr = want; #ifdef HAVE_GETLOADAVG { double avg; if (getloadavg(&avg, 1) == -1) psclog_warn("getloadavg"); // XXX round up nstr = MAX(1, nstr - avg); } #endif return (nstr); }
int zfsslash2_init(void) { struct pscfs_args args = PSCFS_ARGS_INIT(0, NULL); extern struct fuse_lowlevel_ops pscfs_fuse_ops; extern struct fuse_session *fuse_session; extern struct pollfd pscfs_fds[]; extern int newfs_fd[2], pscfs_nfds; extern char *fuse_mount_options; char buf[BUFSIZ]; int rc; rc = snprintf(buf, sizeof(buf), "umount %s", _PATH_KSTAT); if (rc == -1) psc_fatal("snprintf: umount %s", _PATH_KSTAT); if (rc >= (int)sizeof(buf)) psc_fatalx("snprintf: umount %s: too long", _PATH_KSTAT); if (system(buf) == -1) psclog_warn("system(%s)", buf); if (pipe(newfs_fd) == -1) psc_fatal("pipe"); pscfs_fds[0].fd = newfs_fd[0]; pscfs_fds[0].events = POLLIN; pscfs_nfds = 1; fuse_session = fuse_lowlevel_new(&args.pfa_av, &pscfs_fuse_ops, sizeof(pscfs_fuse_ops), NULL); pscthr_init(SLMTHRT_ZFS_KSTAT, slmzfskstatmthr_main, NULL, 0, "slmzfskstatmthr"); fuse_mount_options = ""; rc = libzfs_init_fusesocket(); if (rc == 0) rc = libzfs_init(); atexit(slm_unmount_kstat); return (rc); }
int pfl_getnprocessors(void) { int np = 1; #ifdef SYS_sched_getaffinity /* Linux */ cpu_set_t mask; if (sched_getaffinity(0, sizeof(mask), &mask) == -1) psclog_warn("sched_getaffinity"); else np = CPU_COUNT(&mask); #elif defined(HW_LOGICALCPU) /* MacOS X */ int mib[2]; size_t size; size = sizeof(np); mib[0] = CTL_HW; mib[1] = HW_LOGICALCPU; if (sysctl(mib, 2, &np, &size, NULL, 0) == 0) np = size; #elif defined(HW_NCPU) /* BSD */ int mib[2]; size_t size; size = sizeof(np); mib[0] = CTL_HW; mib[1] = HW_NCPU; if (sysctl(mib, 2, &np, &size, NULL, 0) == 0) np = size; #endif return (np); }
void slm_unmount_kstat(void) { if (pfl_systemf("umount %s", _PATH_KSTAT) == -1) psclog_warn("umount %s", _PATH_KSTAT); }