28.08.2015 Views

The Design and Implementation of the Anykernel and Rump Kernels

1F3KDce

1F3KDce

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

161<br />

int<br />

p2k_node_read(struct puffs_usermount *pu, puffs_cookie_t opc,<br />

uint8_t *buf, <strong>of</strong>f_t <strong>of</strong>fset, size_t *resid, const struct puffs_cred *pcr, int i<strong>of</strong>lag)<br />

{<br />

struct vnode *vp = OPC2VP(opc);<br />

struct kauth_cred *cred = cred_create(pcr);<br />

struct uio *uio = rump_pub_uio_setup(buf, *resid, <strong>of</strong>fset, RUMPUIO_READ);<br />

int rv;<br />

RUMP_VOP_LOCK(vp, LK_SHARED);<br />

rv = RUMP_VOP_READ(vp, uio, i<strong>of</strong>lag, cred);<br />

RUMP_VOP_UNLOCK(vp);<br />

*resid = rump_pub_uio_free(uio);<br />

cred_destroy(cred);<br />

}<br />

return rv;<br />

Figure 3.32: <strong>Implementation</strong> <strong>of</strong> p2k_node_read(). <strong>The</strong> parameters from <strong>the</strong><br />

puffs interface are translated to parameters expected by <strong>the</strong> kernel vnode interface.<br />

Kernel data types are not exposed to userspace, so rump kernel public routines are<br />

used to allocate, initialize <strong>and</strong> release such types.<br />

ences a file using a struct vnode pointer, whereas puffs references one using a<br />

puffs_cookie_t value. Ano<strong>the</strong>r example <strong>of</strong> a difference is <strong>the</strong> way (address, size)-<br />

tuples are indicated. In <strong>the</strong> kernel struct uio is used. In puffs, <strong>the</strong> same information<br />

is passed as separate pointer <strong>and</strong> byte count parameters.<br />

<strong>The</strong> p2k, or puffs-to-kernel, library is a request translator between <strong>the</strong> puffs userspace<br />

file system interface <strong>and</strong> <strong>the</strong> kernel virtual file system interface (manual page p2k.3<br />

at A–12). It also interprets <strong>the</strong> results from <strong>the</strong> kernel file systems <strong>and</strong> converts<br />

<strong>the</strong>m back to a format that puffs underst<strong>and</strong>s.<br />

Most <strong>of</strong> <strong>the</strong> translation done by <strong>the</strong> p2k library is a matter <strong>of</strong> converting data<br />

types back <strong>and</strong> forth. To give an example <strong>of</strong> p2k operation, we discuss reading a<br />

file, which is illustrated by <strong>the</strong> p2k read routine in Figure 3.32. We see <strong>the</strong> uio

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!