Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/md/md.c
Show First 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | |||||
#include <sys/proc.h> | #include <sys/proc.h> | ||||
#include <sys/queue.h> | #include <sys/queue.h> | ||||
#include <sys/rwlock.h> | #include <sys/rwlock.h> | ||||
#include <sys/sbuf.h> | #include <sys/sbuf.h> | ||||
#include <sys/sched.h> | #include <sys/sched.h> | ||||
#include <sys/sf_buf.h> | #include <sys/sf_buf.h> | ||||
#include <sys/sysctl.h> | #include <sys/sysctl.h> | ||||
#include <sys/uio.h> | #include <sys/uio.h> | ||||
#include <sys/unistd.h> | |||||
#include <sys/vnode.h> | #include <sys/vnode.h> | ||||
#include <sys/disk.h> | #include <sys/disk.h> | ||||
#include <geom/geom.h> | #include <geom/geom.h> | ||||
#include <geom/geom_int.h> | #include <geom/geom_int.h> | ||||
#include <vm/vm.h> | #include <vm/vm.h> | ||||
#include <vm/vm_param.h> | #include <vm/vm_param.h> | ||||
▲ Show 20 Lines • Show All 153 Lines • ▼ Show 20 Lines | struct md_s { | ||||
char ident[32]; | char ident[32]; | ||||
unsigned flags; | unsigned flags; | ||||
char name[20]; | char name[20]; | ||||
struct proc *procp; | struct proc *procp; | ||||
struct g_geom *gp; | struct g_geom *gp; | ||||
struct g_provider *pp; | struct g_provider *pp; | ||||
int (*start)(struct md_s *sc, struct bio *bp); | int (*start)(struct md_s *sc, struct bio *bp); | ||||
struct devstat *devstat; | struct devstat *devstat; | ||||
bool candelete; | |||||
/* MD_MALLOC related fields */ | /* MD_MALLOC related fields */ | ||||
struct indir *indir; | struct indir *indir; | ||||
uma_zone_t uma; | uma_zone_t uma; | ||||
/* MD_PRELOAD related fields */ | /* MD_PRELOAD related fields */ | ||||
u_char *pl_ptr; | u_char *pl_ptr; | ||||
size_t pl_len; | size_t pl_len; | ||||
▲ Show 20 Lines • Show All 610 Lines • ▼ Show 20 Lines | mdstart_vnode(struct md_s *sc, struct bio *bp) | ||||
switch (bp->bio_cmd) { | switch (bp->bio_cmd) { | ||||
case BIO_READ: | case BIO_READ: | ||||
auio.uio_rw = UIO_READ; | auio.uio_rw = UIO_READ; | ||||
break; | break; | ||||
case BIO_WRITE: | case BIO_WRITE: | ||||
auio.uio_rw = UIO_WRITE; | auio.uio_rw = UIO_WRITE; | ||||
break; | break; | ||||
case BIO_DELETE: | |||||
case BIO_FLUSH: | case BIO_FLUSH: | ||||
break; | break; | ||||
case BIO_DELETE: | |||||
if (sc->candelete) | |||||
break; | |||||
/* FALLTHROUGH */ | |||||
default: | default: | ||||
return (EOPNOTSUPP); | return (EOPNOTSUPP); | ||||
} | } | ||||
td = curthread; | td = curthread; | ||||
vp = sc->vnode; | vp = sc->vnode; | ||||
pb = NULL; | pb = NULL; | ||||
piov = NULL; | piov = NULL; | ||||
▲ Show 20 Lines • Show All 272 Lines • ▼ Show 20 Lines | |||||
static void | static void | ||||
md_handleattr(struct md_s *sc, struct bio *bp) | md_handleattr(struct md_s *sc, struct bio *bp) | ||||
{ | { | ||||
if (sc->fwsectors && sc->fwheads && | if (sc->fwsectors && sc->fwheads && | ||||
(g_handleattr_int(bp, "GEOM::fwsectors", sc->fwsectors) != 0 || | (g_handleattr_int(bp, "GEOM::fwsectors", sc->fwsectors) != 0 || | ||||
g_handleattr_int(bp, "GEOM::fwheads", sc->fwheads) != 0)) | g_handleattr_int(bp, "GEOM::fwheads", sc->fwheads) != 0)) | ||||
return; | return; | ||||
if (g_handleattr_int(bp, "GEOM::candelete", 1) != 0) | if (g_handleattr_int(bp, "GEOM::candelete", sc->candelete) != 0) | ||||
return; | return; | ||||
if (sc->ident[0] != '\0' && | if (sc->ident[0] != '\0' && | ||||
g_handleattr_str(bp, "GEOM::ident", sc->ident) != 0) | g_handleattr_str(bp, "GEOM::ident", sc->ident) != 0) | ||||
return; | return; | ||||
if (g_handleattr_int(bp, "MNT::verified", (sc->flags & MD_VERIFY) != 0)) | if (g_handleattr_int(bp, "MNT::verified", (sc->flags & MD_VERIFY) != 0)) | ||||
return; | return; | ||||
g_io_deliver(bp, EOPNOTSUPP); | g_io_deliver(bp, EOPNOTSUPP); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 212 Lines • ▼ Show 20 Lines | |||||
static int | static int | ||||
mdcreate_vnode(struct md_s *sc, struct md_req *mdr, struct thread *td) | mdcreate_vnode(struct md_s *sc, struct md_req *mdr, struct thread *td) | ||||
{ | { | ||||
struct vattr vattr; | struct vattr vattr; | ||||
struct nameidata nd; | struct nameidata nd; | ||||
char *fname; | char *fname; | ||||
int error, flags; | int error, flags; | ||||
long v; | |||||
fname = mdr->md_file; | fname = mdr->md_file; | ||||
if (mdr->md_file_seg == UIO_USERSPACE) { | if (mdr->md_file_seg == UIO_USERSPACE) { | ||||
error = copyinstr(fname, sc->file, sizeof(sc->file), NULL); | error = copyinstr(fname, sc->file, sizeof(sc->file), NULL); | ||||
if (error != 0) | if (error != 0) | ||||
return (error); | return (error); | ||||
} else if (mdr->md_file_seg == UIO_SYSSPACE) | } else if (mdr->md_file_seg == UIO_SYSSPACE) | ||||
strlcpy(sc->file, fname, sizeof(sc->file)); | strlcpy(sc->file, fname, sizeof(sc->file)); | ||||
Show All 13 Lines | mdcreate_vnode(struct md_s *sc, struct md_req *mdr, struct thread *td) | ||||
NDFREE(&nd, NDF_ONLY_PNBUF); | NDFREE(&nd, NDF_ONLY_PNBUF); | ||||
if (nd.ni_vp->v_type != VREG) { | if (nd.ni_vp->v_type != VREG) { | ||||
error = EINVAL; | error = EINVAL; | ||||
goto bad; | goto bad; | ||||
} | } | ||||
error = VOP_GETATTR(nd.ni_vp, &vattr, td->td_ucred); | error = VOP_GETATTR(nd.ni_vp, &vattr, td->td_ucred); | ||||
if (error != 0) | if (error != 0) | ||||
goto bad; | goto bad; | ||||
if ((mdr->md_options & MD_AUTOUNMAP) != 0) { | |||||
error = VOP_PATHCONF(nd.ni_vp, _PC_DEALLOC_PRESENT, &v); | |||||
if (error != 0) | |||||
goto bad; | |||||
if (v == 0) | |||||
sc->candelete = false; | |||||
} | |||||
if (VOP_ISLOCKED(nd.ni_vp) != LK_EXCLUSIVE) { | if (VOP_ISLOCKED(nd.ni_vp) != LK_EXCLUSIVE) { | ||||
vn_lock(nd.ni_vp, LK_UPGRADE | LK_RETRY); | vn_lock(nd.ni_vp, LK_UPGRADE | LK_RETRY); | ||||
if (VN_IS_DOOMED(nd.ni_vp)) { | if (VN_IS_DOOMED(nd.ni_vp)) { | ||||
/* Forced unmount. */ | /* Forced unmount. */ | ||||
error = EBADF; | error = EBADF; | ||||
goto bad; | goto bad; | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 240 Lines • ▼ Show 20 Lines | if (mdr->md_label != NULL) | ||||
error = copyinstr(mdr->md_label, sc->label, | error = copyinstr(mdr->md_label, sc->label, | ||||
sizeof(sc->label), NULL); | sizeof(sc->label), NULL); | ||||
if (error != 0) | if (error != 0) | ||||
goto err_after_new; | goto err_after_new; | ||||
if (mdr->md_options & MD_AUTOUNIT) | if (mdr->md_options & MD_AUTOUNIT) | ||||
mdr->md_unit = sc->unit; | mdr->md_unit = sc->unit; | ||||
sc->mediasize = mdr->md_mediasize; | sc->mediasize = mdr->md_mediasize; | ||||
sc->sectorsize = sectsize; | sc->sectorsize = sectsize; | ||||
sc->candelete = true; | |||||
error = EDOOFUS; | error = EDOOFUS; | ||||
switch (sc->type) { | switch (sc->type) { | ||||
case MD_MALLOC: | case MD_MALLOC: | ||||
sc->start = mdstart_malloc; | sc->start = mdstart_malloc; | ||||
error = mdcreate_malloc(sc, mdr); | error = mdcreate_malloc(sc, mdr); | ||||
break; | break; | ||||
case MD_PRELOAD: | case MD_PRELOAD: | ||||
/* | /* | ||||
▲ Show 20 Lines • Show All 456 Lines • Show Last 20 Lines |