diff options
Diffstat (limited to 'usr/src/man/man3vnd')
-rw-r--r-- | usr/src/man/man3vnd/Makefile | 70 | ||||
-rw-r--r-- | usr/src/man/man3vnd/vnd_create.3vnd | 280 | ||||
-rw-r--r-- | usr/src/man/man3vnd/vnd_errno.3vnd | 170 | ||||
-rw-r--r-- | usr/src/man/man3vnd/vnd_frameio_read.3vnd | 705 | ||||
-rw-r--r-- | usr/src/man/man3vnd/vnd_pollfd.3vnd | 155 | ||||
-rw-r--r-- | usr/src/man/man3vnd/vnd_prop_get.3vnd | 242 | ||||
-rw-r--r-- | usr/src/man/man3vnd/vnd_prop_iter.3vnd | 148 | ||||
-rw-r--r-- | usr/src/man/man3vnd/vnd_prop_writeable.3vnd | 101 | ||||
-rw-r--r-- | usr/src/man/man3vnd/vnd_walk.3vnd | 155 |
9 files changed, 2026 insertions, 0 deletions
diff --git a/usr/src/man/man3vnd/Makefile b/usr/src/man/man3vnd/Makefile new file mode 100644 index 0000000000..64abf9dcd6 --- /dev/null +++ b/usr/src/man/man3vnd/Makefile @@ -0,0 +1,70 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet +# at http://www.illumos.org/license/CDDL. +# + +# +# Copyright (c) 2014, Joyent, Inc. All rights reserved. +# + +include $(SRC)/Makefile.master + +MANSECT= 3vnd + +MANFILES= vnd_create.3vnd \ + vnd_errno.3vnd \ + vnd_frameio_read.3vnd \ + vnd_pollfd.3vnd \ + vnd_prop_get.3vnd \ + vnd_prop_iter.3vnd \ + vnd_prop_writeable.3vnd \ + vnd_walk.3vnd + +MANLINKS= frameio_t.3vnd \ + framevec_t.3vnd \ + vnd_close.3vnd \ + vnd_frameio_write.3vnd \ + vnd_open.3vnd \ + vnd_prop_set.3vnd \ + vnd_prop_iter_f.3vnd \ + vnd_strerror.3vnd \ + vnd_strsyserror.3vnd \ + vnd_syserrno.3vnd \ + vnd_unlink.3vnd \ + vnd_walk_cb_f.3vnd + +# vnd_create.3vnd +vnd_open.3vnd := LINKSRC = vnd_create.3vnd +vnd_unlink.3vnd := LINKSRC = vnd_create.3vnd +vnd_close.3vnd := LINKSRC = vnd_create.3vnd + +# vnd_errno.3vnd +vnd_strerror.3vnd := LINKSRC = vnd_errno.3vnd +vnd_syserrno.3vnd := LINKSRC = vnd_errno.3vnd +vnd_strsyserror.3vnd := LINKSRC = vnd_errno.3vnd + +# vnd_frameio_read.3vnd +vnd_frameio_write.3vnd := LINKSRC = vnd_frameio_read.3vnd +framevec_t.3vnd := LINKSRC = vnd_frameio_read.3vnd +frameio_t.3vnd := LINKSRC = vnd_frameio_read.3vnd + +# vnd_prop_get.3vnd +vnd_prop_set.3vnd := LINKSRC = vnd_prop_get.3vnd + +# vnd_prop_iter.3vnd +vnd_prop_iter_f.3vnd := LINKSRC = vnd_prop_iter.3vnd + +# vnd_walk.3vnd +vnd_walk_cb_f.3vnd := LINKSRC = vnd_walk.3vnd + +.KEEP_STATE: + +include $(SRC)/man/Makefile.man + +install: $(ROOTMANFILES) $(ROOTMANLINKS) diff --git a/usr/src/man/man3vnd/vnd_create.3vnd b/usr/src/man/man3vnd/vnd_create.3vnd new file mode 100644 index 0000000000..d29237a60c --- /dev/null +++ b/usr/src/man/man3vnd/vnd_create.3vnd @@ -0,0 +1,280 @@ +'\" te +.\" +.\" This file and its contents are supplied under the terms of the +.\" Common Development and Distribution License ("CDDL"), version 1.0. +.\" You may only use this file in accordance with the terms of version +.\" 1.0 of the CDDL. +.\" +.\" A full copy of the text of the CDDL should have accompanied this +.\" source. A copy of the CDDL is also available via the Internet at +.\" http://www.illumos.org/license/CDDL. +.\" +.\" +.\" Copyright (c) 2014, Joyent, Inc. All rights reserved. +.\" +.TH VND_CREATE 3VND "Feb 21, 2014" + +.SH NAME + +vnd_create, vnd_open, vnd_unlink, vnd_close \- create, open, and destroy +vnd devices + +.SH SYNOPSIS + +.LP +.nf +cc [ flag... ] file... -lvnd [ library... ] +#include <libvnd.h> + +vnd_handle_t *vnd_create(const char *zonename, const char *datalink, + const char *linkname, vnd_errno_t *vnderr, int *syserr); + +vnd_handle_t *vnd_open(const char *zonename, const char *linkname, + vnd_errno_t *vnderr, int *syserr); + +int vnd_unlink(vnd_handle_t *vhp); + +void vnd_close(vnd_handle_t *vhp); +.fi + + +.SH DESCRIPTION +.LP +These functions create vnd devices, obtain handles to extant vnd +devices, and close handles to vnd devices, for use with the rest of +libvnd(3LIB). + +.LP +The vnd_create function creates a new vnd device in the zone specified +by zonename. The zone name argument may be null, in which case the +caller's current zone is used instead. The vnd device and data link it +is created over must both be in the same zone. The datalink argument +indicates the name of the DLPI data link to create the vnd device over. +The linkname argument indicates the name of the new vnd device. The +linkname argument must be less than VND_NAMELEN characters long, +excluding the null terminator. It should be an alphanumeric string. The +only non-alphanumeric characters allowed are ':', '-', and \'_'. +Neither the datalink argument nor linkname argument may be NULL. A +handle to the created device is returned to the caller. Once the +vnd_create function returns, the device can be subsequently opened with +a call to vnd_open. The named device persists until a call to vnd_unlink +or the containing zone is halted. Creating a vnd device requires +PRIV_SYS_NET_CONFIG as well as PRIV_RAWACCESS. The arguments vnderr and +syserr are used to obtain errors in the cases where the call to +vnd_create fails. Both arguments may be NULL pointers, in which case the +more detailed error information is discarded. + +.LP +The vnd_open function opens an existing vnd device and returns a +unique handle to that device. The vnd device to open is specified by +both zonename and linkname. The zonename argument specifies what zone +to look for the vnd device in. The linkname specifies the name of the +link. The zonename argument may be NULL. If it is, the current zone is +used. Similar to vnd_create, the integer values pointed to by the +arguments vnderr and syserr will be filled in with additional error +information in the cases where a call to vnd_open fails. Both +arguments may be NULL to indicate that the error information is not +requested, though this is not recommended. + +.LP +The vnd_unlink function unlinks the vnd device specified by the vnd +handle vhp. This unlink is similar to the use of unlink in a file +system. After a call to unlink, the vnd device will no longer be +accessible by callers to vnd_open and the name will be available for +use in vnd_create. However, the device will continue to exist until +all handles to the device have been closed. + +.LP +The vnd_close function relinquishes the vnd device referenced by the +handle vhp. After a call to vnd_close, the handle is invalidated and +must not be used by the consumer again. The act of calling vnd_close +on a handle does not remove the device. The device is persisted as +long as vnd_unlink has not been called on the device or the containing +zone has not been destroyed. + +.SH RETURN VALUES + +.LP +Upon successful completion, the functions vnd_create and vnd_open +return a pointer to a vnd_handle_t. This handle is used for all +subsequent library operations. If either function fails, then a NULL +pointer is returned and more detailed error information is filled into +the integers pointed to by vnderr and syserr. The vnderr and syserr +correspond to the values that would normally be returned by a call to +vnd_errno(3VND) and vnd_syserrno(3VND). For the full list of possible +errors see libvnd(3LIB). + +.LP +The vnd_unlink function returns zero on success and -1 on failure. On +failure, the vnd and system errnos are updated and available through +the vnd_errno(3VND) and vnd_syserrno(3VND) functions. + +.LP +The vnd_close function does not return any values nor does it set +vnderr or syserr. The handle passed to vnd_close can no longer be +used. + +.SH EXAMPLES +.LP +Example 1 Creating a device +.sp +.LP + +The following sample C program shows how to create a vnd device over +an existing datalink named "net0" that other applications can open +and use as "vnd0". + +.sp +.in +2 +.nf +#include <libvnd.h> +#include <stdio.h> + +int +main(void) +{ + vnd_handle_t *vhp; + vnd_errno_t vnderr; + int syserr; + + /* Errors are considered fatal */ + vhp = vnd_create(NULL, "net0", "vnd0", &vnderr, &syserr); + + if (vhp == NULL) { + if (vnderr == VND_E_SYS) + (void) fprintf(stderr, "failed to create device: %s", + vnd_strsyserror(syserr)); + else + (void) fprintf(stderr, "failed to create device: %s", + vnd_strerror(vnderr)); + return (1); + } + + (void) printf("successfully created vnd0\n"); + vnd_close(vhp); + return (0); +} +.fi +.in -2 + +.LP +Example 2 Opening an existing device in another zone +.sp +.LP + +The following sample C program opens the device named "vnd1" in the zone +named "turin" for further use. + +.sp +.in +2 +.nf +#include <libvnd.h> +#include <stdio.h> + +int +main(void) +{ + vnd_handle_t *vhp; + vnd_errno_t vnderr; + int syserr, ret; + + vhp = vnd_open("turin", "vnd1", &vnderr, &syserr); + if (vhp != NULL) { + if (vnderr == VND_E_SYS) + (void) fprintf(stderr, "failed to open device: %s", + vnd_strsyserror(syserr)); + else + (void) fprintf(stderr, "failed to open device: %s", + vnd_strerror(vnderr)); + return (1); + } + + /* + * Use the device vnd1 with the handle vhp with any of + * the other interfaces documented in libvnd(3LIB) here. + * + * After an arbitrary amount of code, the program will + * set the variable ret with the exit code for the + * program and should execute the following code before + * returning. + */ + vnd_close(vhp); + return (ret); +} +.fi +.in -2 + + +.LP +Example 3 Removing a device +.sp +.LP + +The following sample C program removes a vnd device named vnd0. This +program makes it so no additional programs can access the device. +However, if anyone is actively using it, it will still exist, +similar to calling unlink(2). + +.sp +.in +2 +.nf +#include <libvnd.h> +#include <stdio.h> + +int +main(void) +{ + vnd_handle_t *vhp; + vnd_errno_t vnderr; + int syserr, ret; + + vhp = vnd_open(NULL, "vnd0", &vnderr, &syserr); + if (vhp != NULL) { + if (vnderr == VND_E_SYS) + (void) fprintf(stderr, "failed to open device: %s", + vnd_strsyserror(syserr)); + else + (void) fprintf(stderr, "failed to open device: %s", + vnd_strerror(vnderr)); + return (1); + } + + if (vnd_unlink(vhp) != 0) { + if (vnderr == VND_E_SYS) + (void) fprintf(stderr, "failed to unlink device: %s", + vnd_strsyserror(syserr)); + else + (void) fprintf(stderr, "failed to unlink device: %s", + vnd_strerror(vnderr)); + ret = 1; + } else { + (void) printf("successfully unlinked vnd0!\n"); + ret = 0; + } + + vnd_close(vhp); + return (ret); +} +.fi +.in -2 + +.SH ATTRIBUTES +.sp +.LP +See attributes(5) for descriptions of the following attributes: + +.sp +.TS +box; +c | c +l | l . +ATTRIBUTE TYPE ATTRIBUTE VALUE +_ +Stability Committed +_ +MT-Level See "THREADING" in libvnd(3LIB) +.TE + +.SH SEE ALSO + +libvnd(3LIB), vnd_errno(3VND), vnd_syserrno(3VND), attributes(5), privileges(5) diff --git a/usr/src/man/man3vnd/vnd_errno.3vnd b/usr/src/man/man3vnd/vnd_errno.3vnd new file mode 100644 index 0000000000..ddd6126dd1 --- /dev/null +++ b/usr/src/man/man3vnd/vnd_errno.3vnd @@ -0,0 +1,170 @@ +'\" te +.\" +.\" This file and its contents are supplied under the terms of the +.\" Common Development and Distribution License ("CDDL"), version 1.0. +.\" You may only use this file in accordance with the terms of version +.\" 1.0 of the CDDL. +.\" +.\" A full copy of the text of the CDDL should have accompanied this +.\" source. A copy of the CDDL is also available via the Internet at +.\" http://www.illumos.org/license/CDDL. +.\" +.\" +.\" Copyright (c) 2014, Joyent, Inc. All rights reserved. +.\" +.TH VND_ERRNO 3VND "Feb 21, 2014" + +.SH NAME + +vnd_errno, vnd_syserrno, vnd_strerror, vnd_strsyserror \- obtain and +translate vnd errors + + +.SH SYNOPSIS + +.LP +.nf +cc [ flag... ] file... -lvnd [ library... ] +#include <libvnd.h> + +uint32_t vnd_errno(vnd_handle_t *vhp); + +const char *vnd_strerror(vnd_errno_t err); + +int vnd_syserrno(vnd_handle_t *vhp); + +const char *vnd_strsyserror(int syserr); +.fi + +.SH DESCRIPTION + +.LP +The libvnd(3LIB) library supports a complementary array of errors that +give more specific error information than the traditional set of +system errors available via errno(3C). When an error occurs, consumers +should call the vnd_errno function first and check its value. If the +value of the vnd_errno_t is VND_E_SYS, then the system errno should be +checked. If the vnd_errno_t is not VND_E_SYS, then the contents of the +system errno returned from vnd_syserrno are undefined. Both the vnd +and system errors are only valid for a given handle after a libvnd +library function returned an error and before another libvnd library +function is called on the same handle. The act of making an additional +function call with the same vnd_handle_t invalidates any prior vnd or +system error numbers. For the full list of valid vnd errors see +libvnd(3LIB). For the full list of valid system errors, see Intro(2). + +.LP +The vnd_errno and vnd_syserrno functions retrieve the most recent vnd +and syserr error number respectively from a vnd handle vhp. + +.LP +The vnd_strerror function translates a vnd_errno_t err to a +corresponding string and returns a pointer to that constant string. + +.LP +The vnd_syserrno function is analogous to the vnd_strerror function, +except that it translates a system error back to a string. + + +.SH RETURN VALUES + +.LP +The vnd_errno function returns a vnd_errno_t which contains the vnd +error information. + +.LP +The vnd_syserror function returns an integer which contains the system +error information. These values are the same as those returned by +errno(3C). + +.LP +The vnd_strerror function returns a pointer to a constant string. If +the error passed in is unknown, the string "unknown error" is +returned. + +.LP +The vnd_strsyserror function returns a pointer to the translated +constant string. If an unknown error number is passed, it returns the +string "Unknown error". If an error occurs, it returns a NULL pointer. + +.SH EXAMPLES + +.LP +Example 1 Obtaining errors from a vnd_handle_t + +.sp +.LP +The following sample C function, which can be incorporated into a larger +program, shows how to obtain the vnd and system errors from a +vnd_handle_t after a vnd interface on a handle failed. + +.sp +.in +2 +.nf +#include <libvnd.h> + +static void +print_errnos(vnd_handle_t *vhp) +{ + vnd_errno_t vnderr; + int syserr; + + vnderr = vnd_errno(vhp); + syserr = vnd_syserrno(vhp); + + (void) printf("vnd err: %d, sys err: %d\n", + vnderr, syserr); +} +.fi +.in -2 + +.LP +Example 2 A perror-like function + +.sp +.LP +The following sample C function which can be incorporated into a +larger program shows how to write a perror-like function to print +out error messages for a vnd device. + +.sp +.in +2 +.nf +#include <libvnd.h> + +static void +sample_perror(const char *msg, vnd_error_t vnderr, int syserr) +{ + (void) fprintf(stderr, "%s: %s", msg, + vnderr != VND_E_SYS ? vnd_strerror(vnderr) : + vnd_strsyserror(syserr)); +} +.fi +.in -2 + +.SH ATTRIBUTES +.sp +.LP +See attributes(5) for descriptions of the following attributes: + +.sp +.TS +box; +c | c +l | l . +ATTRIBUTE TYPE ATTRIBUTE VALUE +_ +Stability Committed +_ +MT-Level See below +.TE + +.LP +The MT-Level of the functions vnd_strerror and vnd_strsyserror is +MT-Safe. See "THREADING" in libvnd(3LIB) for a discussion of the +MT-Level of vnd_errno and vnd_syserrno. + + +.SH SEE ALSO + +Intro(2), errno(3C), libvnd(3LIB), attributes(5) diff --git a/usr/src/man/man3vnd/vnd_frameio_read.3vnd b/usr/src/man/man3vnd/vnd_frameio_read.3vnd new file mode 100644 index 0000000000..5fc65c96a3 --- /dev/null +++ b/usr/src/man/man3vnd/vnd_frameio_read.3vnd @@ -0,0 +1,705 @@ +'\" te +.\" +.\" This file and its contents are supplied under the terms of the +.\" Common Development and Distribution License ("CDDL"), version 1.0. +.\" You may only use this file in accordance with the terms of version +.\" 1.0 of the CDDL. +.\" +.\" A full copy of the text of the CDDL should have accompanied this +.\" source. A copy of the CDDL is also available via the Internet at +.\" http://www.illumos.org/license/CDDL. +.\" +.\" +.\" Copyright (c) 2014, Joyent, Inc. All rights reserved. +.\" +.TH VND_FRAMEIO_READ 3VND "Mar 06, 2014" + +.SH NAME + +vnd_frameio_read, vnd_frameio_write \- perform framed I/O to a vnd device + +.SH SYNOPSIS + +.LP +.nf +cc [ flag... ] file... -lvnd [ library... ] +#include <libvnd.h> + +int vnd_frameio_read(vnd_handle_t *vhp, frameio_t *fiop); + +int vnd_frameio_write(vnd_handle_t *vhp, frameio_t *fiop); +.fi + +.SH DESCRIPTION +.LP +Framed I/O is a general means to manipulate data that is inherently +framed, meaning that there is a maximum frame size, but the data may +often be less than that size. As an example, an Ethernet device's MTU +describes the maximum frame size, but the size of an individual frame +is often much less. You can read a single frame at a time, or you can +read multiple frames in a single call. + +In addition, framed I/O allows the consumer to break individual frames +into a series of vectors. This is analogous to the use of an iovec(9S) +with readv(2) and writev(2). + +vnd_frameio_read performs a framed I/O read of the device represented by +the handle vhp, with the framed I/O data described by fiop. +vnd_frameio_write works in the same manner, except performing a write +instead of a read. + +.LP +The basic vector component of the frameio_t is the framevec_t. Each +framevec_t represents a single vector entry. An array of these is +present in the frameio_t. The framevec_t structure has the following +members: + +.in +2 +.nf +void *fv_buf /* data buffer */ +size_t fv_buflen; /* total size of buffer */ +size_t fv_actlen; /* amount of buffer consumed */ +.fi +.in -2 + +.LP +The fv_buf member points to a buffer which contains the data for this +individual vector. When reading, data is consumed from fv_buf. When +writing, data is written into fv_buf. + +The fv_buflen should indicate the total amount of data that is in the +buffer. When reading, it indicates the size of the buffer. It must be +set prior to calling vnd_frameio_read(). When writing, it indicates the +amount of data that is valid in the buffer. + +The fv_actlen is a read-only member. It is set on successful return of +the functions vnd_frameio_read and vnd_frameio_write. When reading, it +is updated with the amount of data that was read into fv_buf. When +writing, it is instead updated with the amount of data from fv_buf that +was actually consumed. Generally when writing data, a framevec_t will +either be entirely consumed or it will not be consumed at all. + + +.LP +A series of framevec_t's is encapsulated in a frameio_t. The frameio_t +structure has the following members: + +.in +2 +.nf +uint_t fio_version; /* current version */ +uint_t fio_nvpf; /* number of vectors in one frame */ +uint_t fio_nvecs; /* The total number of vectors */ +framevec_t fio_vecs[]; /* vectors */ +.fi +.in -2 + +.LP +The fio_version member represents the current version of the frameio_t. +The fio_version should be set to the macro FRAMEIO_CURRENT_VERSION, +which is currently 1. + +The members fio_nvpf and fio_nvecs describe the number of frames that +exist. fio_nvecs describes the total number of vectors that are present +in fio_vecs. The upper bound on this is described by FRAMEIO_NVECS_MAX +which is currently 32. fio_nvpf describe the number of vectors that +should be used to make up each frame. By setting fio_vecs to be an even +multiple of fio_nvpf, multiple frames can be read or written in a single +call. + +After a call to vnd_frameio_read or vnd_frameio_write fio_nvecs is +updated with total number of vectors read or written to. This value can +be divided by fio_nvpf to determine the total number of frames that were +written or read. + +.LP +Each frame can be broken down into a series of multiple vectors. As an +example, someone might want to break Ethernet frames into mac headers +and payloads. The value of fio_nvpf would be set to two, to indicate +that a single frame consists of two different vector components. The +member fio_nvecs describes the total number of frames. As such, the +value of fio_vecs divided by fio_nvpf describes the total number of +frames that can be consumed in one call. As a result of this, fio_nvpf +must evenly divide fio_vecs. If fio_nvpf is set to two and +fio_nvecs is set to ten, then a total of five frames can be processed +at once, each frame being broken down into two different vector +components. + +A given frame will never overflow the number of vectors described by +fio_nvpf. Consider the case where each vector component has a buffer +sized to 1518 bytes, fio_nvpf is set to one, and fio_nvecs is set to +three. If a call to vnd_frameio_read is made and four 500 byte Ethernet +frames come in, then each frame will be mapped to a single vector. The +500 bytes will be copied into fio_nvecs[i]->fio_buf and +fio_nvecs[i]->fio_actlen will be set to 500. To contrast this, if +readv(2) had been called, the first three frames would all be in the +first iov and the fourth frame's first eight bytes would be in the first +iov and the remaining in the second. + +.LP +The user must properly initialize fio_nvecs framevec_t's worth of the +fio_vecs array. When multiple vectors comprise a frame, fv_buflen data +is consumed before moving onto the next vector. Consider the case +where the user wants to break a vector into three different +components, an 18 byte vector for an Ethernet VLAN header, a 20 byte +vector for an IPv4 header, and a third 1500 byte vector for the +remaining payload. If a frame was received that only had 30 bytes, +then the first 18 bytes would fill up the first vector, the remaining +12 bytes would fill up the IPv4 header. If instead a 524 byte frame +came in, then the first 18 bytes would be placed in the first vector, +the next 24 bytes would be placed in the next vector, and the remaining +500 bytes in the third. + +.LP +The functions vnd_frameio_read and vnd_frameio_write operate in both +blocking and non-blocking mode. If either O_NONBLOCK or O_NDELAY have +been set on the file descriptor, then the I/O will behave in +non-blocking mode. When in non-blocking mode, if no data is available +when vnd_frameio_read is called, EAGAIN is returned. When +vnd_frameio_write is called in non-blocking mode, if sufficient buffer +space to hold all of the output frames is not available, then +vnd_frameio_write will return EAGAIN. To know when the given vnd device +has sufficient space, the device fires POLLIN/POLLRDNORM when data is +available for read and POLLOUT/POLLRDOUT when space in the buffer has +opened up for write. These events can be watched for through +port_associate(3C) and similar routines with a file descriptor returned +from vnd_polfd(3VND). + +.LP +When non-blocking mode is disabled, calls to vnd_frameio_read will +block until some amount of data is available. Calls to +vnd_frameio_write will block until sufficient buffer space is +available. + +.LP +Similar to read(2) and write(2), vnd_frameio_read and +vnd_frameio_write make no guarantees about the ordering of data when +multiple threads simultaneously call the interface. While the data +itself will be atomic, the ordering of multiple simultaneous calls is +not defined. + +.SH RETURN VALUES + +.LP +The vnd_frameio_read function returns zero on success. The member +fio_nvecs of fiop is updated with the total number of vectors that had +data read into them. Each updated framevec_t will have the buffer +pointed to by fv_buf filled in with data, and fv_actlen will be +updated with the amount of valid data in fv_buf. + +.LP +The vnd_frameio_write function returns zero on success. The member +fio_nvecs of fiop is updated with the total number of vectors that +were written out to the underlying datalink. The fv_actlen of each +vector is updated to indicate the amount of data that was written from +that buffer. + +.LP +On failure, both vnd_frameio_read and vnd_frameio_write return -1. The +vnd and system error numbers are updated and available via +vnd_errno(3VND) and vnd_syserrno(3VND). See ERRORS below for a list of +errors and their meaning. + + +.SH ERRORS +.LP +The functions vnd_frameio_read and vnd_frameio_write always set the +vnd error to VND_E_SYS. The following system errors will be +encountered: + +.sp +.ne 2 +.na +EAGAIN +.ad +.RS 10n +Insufficient system memory was available for the operation. +.sp +Non-blocking mode was enabled and during the call to vnd_frameio_read, +no data was available. Non-blocking mode was enabled and during the call +to vnd_frameio_write, insufficient buffer space was available. +.RE + +.sp +.ne 2 +.na +ENXIO +.ad +.RS 10n +The vnd device referred to by vhp is not currently attached to an +underlying data link and cannot send data. +.RE + +.sp +.ne 2 +.na +EFAULT +.ad +.RS 10n +The fiop argument points to an illegal address or the fv_buf members of +the framevec_t's associated with the fiop member fio_vecs point to +illegal addresses. +.RE + +.sp +.ne 2 +.na +EINVAL +.ad +.RS 10n +The fio_version member of fiop was unknown, the number of vectors +specified by fio_nvecs is zero or greater than FRAMEIO_NVECS_MAX, +fio_nvpf equals zero, fio_nvecs is not evenly divisible by fio_nvpf, or +a buffer in fio_vecs[] has set fv_buf or fv_buflen to zero. +.RE + + +.sp +.ne 2 +.na +EINTR +.ad +.RS 10n +A signal was caught during vnd_frameio_read or vnd_frameio_write, and no +data was transferred. +.RE + + +.sp +.ne 2 +.na +EOVERFLOW +.ad +.RS 10n +During vnd_frameio_read, the size of a frame specified by fiop->fio_nvpf +and fiop->fio_vecs[].fv_buflen cannot contain a frame. +.sp +In a ILP32 environment, more data than UINT_MAX would be set in +fv_actlen. +.RE + + +.sp +.ne 2 +.na +ERANGE +.ad +.RS 10n +During vnd_frameio_write, the size of a frame is less than the device's +minimum transmission unit or it is larger than the size of the maximum +transmission unit. +.RE + + +.SH EXAMPLES + +.LP +Example 1 Read a single frame with a single vector + +.sp +.LP +The following sample C program opens an existing vnd device named +"vnd0" in the current zone and performs a blocking read of a single +frame from it. + +.sp +.in +2 +.nf +#include <libvnd.h> +#include <stdio.h> + +int +main(void) +{ + vnd_handle_t *vhp; + vnd_errno_t vnderr; + int syserr, i; + frameio_t *fiop; + + fiop = malloc(sizeof (frameio_t) + sizeof (framevec_t)); + if (fiop == NULL) { + perror("malloc frameio_t"); + return (1); + } + fiop->fio_version = FRAMEIO_CURRENT_VERSION; + fiop->fio_nvpf = 1; + fiop->fio_nvecs = 1; + fiop->fio_vecs[0].fv_buf = malloc(1518); + fiop->fio_vecs[0].fv_buflen = 1518; + if (fiop->fio_vecs[0].fv_buf == NULL) { + perror("malloc framevec_t.fv_buf"); + free(fiop); + return (1); + } + + vhp = vnd_open(NULL, "vnd1", &vnderr, &syserr); + if (vhp != NULL) { + if (vnderr == VND_E_SYS) + (void) fprintf(stderr, "failed to open device: %s", + vnd_strsyserror(syserr)); + else + (void) fprintf(stderr, "failed to open device: %s", + vnd_strerror(vnderr)); + free(fiop->fio_vecs[0].fv_buf); + free(fiop); + return (1); + } + + if (frameio_read(vhp, fiop) != 0) { + vnd_errno_t vnderr = vnd_errno(vhp); + int syserr = vnd_syserrno(vhp); + + /* Most consumers should retry on EINTR */ + if (vnderr == VND_E_SYS) + (void) fprintf(stderr, "failed to read: %s", + vnd_strsyserror(syserr)); + else + (void) fprintf(stderr, "failed to read: %s", + vnd_strerror(vnderr)); + vnd_close(vhp); + free(fiop->fio_vecs[0].fv_buf); + free(fiop); + return (1); + } + + + /* Consume the data however it's desired */ + (void) printf("received %d bytes\n", fiop->fio_vecs[0].fv_actlen); + for (i = 0; i < fiop->fio_vecs[0].fv_actlen) + (void) printf("%x ", fiop->fio_vecs[0].fv_buf[i]); + + vnd_close(vhp); + free(fiop->fio_vecs[0].fv_buf); + free(viop); + return (0); +} +.fi +.in -2 + +.LP +Example 2 Write a single frame with a single vector +.sp +.LP +The following sample C program opens an existing vnd device named +"vnd0" in the current zone and performs a blocking write of a single +frame to it. + +.sp +.in +2 +.nf +#include <libvnd.h> +#include <stdio.h> +#include <string.h> + +int +main(void) +{ + vnd_handle_t *vhp; + vnd_errno_t vnderr; + int syserr; + frameio_t *fiop; + + fiop = malloc(sizeof (frameio_t) + sizeof (framevec_t)); + if (fiop == NULL) { + perror("malloc frameio_t"); + return (1); + } + fiop->fio_version = FRAMEIO_CURRENT_VERSION; + fiop->fio_nvpf = 1; + fiop->fio_nvecs = 1; + fiop->fio_vecs[0].fv_buf = malloc(1518); + if (fiop->fio_vecs[0].fv_buf == NULL) { + perror("malloc framevec_t.fv_buf"); + free(fiop); + return (1); + } + + /* + * Fill in your data however you desire. This is an entirely + * invalid frame and while the frameio write may succeed, the + * networking stack will almost certainly drop it. + */ + (void) memset(fiop->fio_vecs[0].fv_buf, 'r', 1518); + fiop->fio_vecs[0].fv_buflen = 1518; + + vhp = vnd_open(NULL, "vnd0", &vnderr, &syserr); + if (vhp != NULL) { + if (vnderr == VND_E_SYS) + (void) fprintf(stderr, "failed to open device: %s", + vnd_strsyserror(syserr)); + else + (void) fprintf(stderr, "failed to open device: %s", + vnd_strerror(vnderr)); + free(fiop->fio_vecs[0].fv_buf); + free(fiop); + return (1); + } + + if (frameio_write(vhp, fiop) != 0) { + /* Most consumers should retry on EINTR */ + if (vnderr == VND_E_SYS) + (void) fprintf(stderr, "failed to write: %s", + vnd_strsyserror(syserr)); + else + (void) fprintf(stderr, "failed to write: %s", + vnd_strerror(vnderr)); + vnd_close(vhp); + free(fiop->fio_vecs[0].fv_buf); + free(fiop); + return (1); + } + + + (void) printf("wrote %d bytes\n", fiop->fio_vecs[0].fv_actlen); + + vnd_close(vhp); + free(fiop->fio_vecs[0].fv_buf); + free(viop); + return (0); +} +.fi +.in -2 + +.LP +Example 3 Read frames comprised of multiple vectors +.sp +.LP +The following sample C program is similar to example 1, except instead +of reading a single frame consisting of a single vector it reads +multiple frames consisting of two vectors. The first vector has room for +an 18 byte VLAN enabled Ethernet header and the second vector has room +for a 1500 byte payload. + +.sp +.in +2 +.nf +#include <libvnd.h> +#include <stdio.h> + +int +main(void) +{ + vnd_handle_t *vhp; + vnd_errno_t vnderr; + int syserr, i, nframes; + frameio_t *fiop; + + /* Allocate enough framevec_t's for 5 frames */ + fiop = malloc(sizeof (frameio_t) + sizeof (framevec_t) * 10); + if (fiop == NULL) { + perror("malloc frameio_t"); + return (1); + } + fiop->fio_version = FRAMEIO_CURRENT_VERSION; + fiop->fio_nvpf = 2; + fiop->fio_nvecs = 10; + for (i = 0; i < 10; i += 2) { + fiop->fio_vecs[i].fv_buf = malloc(18); + fiop->fio_vecs[i].fv_buflen = 18; + if (fiop->fio_vecs[i].fv_buf == NULL) { + perror("malloc framevec_t.fv_buf"); + /* Perform appropriate memory cleanup */ + return (1); + } + fiop->fio_vecs[i+1].fv_buf = malloc(1500); + fiop->fio_vecs[i+1].fv_buflen = 1500; + if (fiop->fio_vecs[i+1].fv_buf == NULL) { + perror("malloc framevec_t.fv_buf"); + /* Perform appropriate memory cleanup */ + return (1); + } + } + + vhp = vnd_open(NULL, "vnd1", &vnderr, &syserr); + if (vhp != NULL) { + if (vnderr == VND_E_SYS) + (void) fprintf(stderr, "failed to open device: %s", + vnd_strsyserror(syserr)); + else + (void) fprintf(stderr, "failed to open device: %s", + vnd_strerror(vnderr)); + /* Perform appropriate memory cleanup */ + return (1); + } + + if (frameio_read(vhp, fiop) != 0) { + /* Most consumers should retry on EINTR */ + if (vnderr == VND_E_SYS) + (void) fprintf(stderr, "failed to read: %s", + vnd_strsyserror(syserr)); + else + (void) fprintf(stderr, "failed to read: %s", + vnd_strerror(vnderr)); + vnd_close(vhp); + /* Perform appropriate memory cleanup */ + return (1); + } + + /* Consume the data however it's desired */ + nframes = fiop->fio_nvecs / fiop->fio_nvpf; + (void) printf("consumed %d frames!\n", nframes); + for (i = 0; i < nframes; i++) { + (void) printf("received %d bytes of Ethernet Header\n", + fiop->fio_vecs[i].fv_actlen); + (void) printf("received %d bytes of payload\n", + fiop->fio_vecs[i+1].fv_actlen); + } + + vnd_close(vhp); + /* Do proper memory cleanup */ + return (0); +} +.fi +.in -2 + +.LP +Example 4 Perform non-blocking reads of multiple frames with a +single vector +.sp +.LP +In this sample C program, opens an existing vnd device named "vnd0" in +the current zone, ensures that it is in non-blocking mode, and uses +event ports to do device reads. + +.sp +.in +2 +.nf +#include <libvnd.h> +#include <stdio.h> +#include <port.h> +#include <unistd.h> +#include <errno.h> +#include <sys/tpyes.h> +#include <fcntl.h> + +int +main(void) +{ + vnd_handle_t *vhp; + vnd_errno_t vnderr; + int syserr, i, nframes, port, vfd; + frameio_t *fiop; + + port = port_create(); + if (port < 0) { + perror("port_create"); + return (1); + } + /* Allocate enough framevec_t's for 10 frames */ + fiop = malloc(sizeof (frameio_t) + sizeof (framevec_t) * 10); + if (fiop == NULL) { + perror("malloc frameio_t"); + (void) close(port); + return (1); + } + fiop->fio_version = FRAMEIO_CURRENT_VERSION; + fiop->fio_nvpf = 1; + fiop->fio_nvecs = 10; + for (i = 0; i < 10; i++) { + fiop->fio_vecs[i].fv_buf = malloc(1518); + fiop->fio_vecs[i].fv_buflen = 1518; + if (fiop->fio_vecs[i].fv_buf == NULL) { + perror("malloc framevec_t.fv_buf"); + /* Perform appropriate memory cleanup */ + (void) close(port); + return (1); + } + } + + vhp = vnd_open(NULL, "vnd1", &vnderr, &syserr); + if (vhp != NULL) { + if (vnderr == VND_E_SYS) + (void) fprintf(stderr, "failed to open device: %s", + vnd_strsyserror(syserr)); + else + (void) fprintf(stderr, "failed to open device: %s", + vnd_strerror(vnderr)); + /* Perform appropriate memory cleanup */ + (void) close(port); + return (1); + } + vfd = vnd_pollfd(vhp); + if (fcntl(fd, F_SETFL, O_NONBLOCK) != 0) { + (void) fprintf(stderr, "failed to enable non-blocking mode: %s", + strerrror(errno)); + } + + for (;;) { + port_event_t pe; + + if (port_associate(port, PORT_SOURCE_FD, vfd, POLLIN, + vhp) != 0) { + perror("port_associate"); + vnd_close(vhp); + /* Perform appropriate memory cleanup */ + (void) close(port); + return (1); + } + + if (port_get(port, &pe, NULL) != 0) { + if (errno == EINTR) + continue; + perror("port_associate"); + vnd_close(vhp); + /* Perform appropriate memory cleanup */ + (void) close(port); + return (1); + } + + /* + * Most real applications will need to compare the file + * descriptor and switch on it. In this case, assume + * that the fd in question that is readable is 'vfd'. + */ + if (frameio_read(pe.portev_user, fiop) != 0) { + vnd_errno_t vnderr = vnd_errno(vhp); + int syserr = vnd_syserrno(vhp); + + if (vnderr == VND_E_SYS && (syserr == EINTR || + syserr == EAGAIN)) + continue; + (void) fprintf(stderr, "failed to get read: %s", + vnd_strsyserror(vnderr)); + vnd_close(vhp); + /* Perform appropriate memory cleanup */ + (void) close(port); + return (1); + } + + /* Consume the data however it's desired */ + nframes = fiop->fio_nvecs / fiop->fio_nvpf; + for (i = 0; i < nframes; i++) { + (void) printf("frame %d is %d bytes large\n", i, + fiop->fio_vecs[i].fv_actlen); + } + + } + + vnd_close(vhp); + /* Do proper memory cleanup */ + return (0); +} +.fi +.in -2 + +.SH ATTRIBUTES +.LP +See attributes(5) for descriptions of the following attributes: + +.sp +.TS +box; +c | c +l | l . +ATTRIBUTE TYPE ATTRIBUTE VALUE +_ +Stability Committed +_ +MT-Level See "THREADING" in libvnd(3LIB) +.TE + + +.SH SEE ALSO + +Intro(2), getmsg(2), read(2), readv(2), write(2), writev(2), +libvnd(3VND), vnd_errno(3VND), vnd_pollfd(3VND), vnd_syserrno(3VND), +iovec(9S) diff --git a/usr/src/man/man3vnd/vnd_pollfd.3vnd b/usr/src/man/man3vnd/vnd_pollfd.3vnd new file mode 100644 index 0000000000..500d3bac99 --- /dev/null +++ b/usr/src/man/man3vnd/vnd_pollfd.3vnd @@ -0,0 +1,155 @@ +'\" te +.\" +.\" This file and its contents are supplied under the terms of the +.\" Common Development and Distribution License ("CDDL"), version 1.0. +.\" You may only use this file in accordance with the terms of version +.\" 1.0 of the CDDL. +.\" +.\" A full copy of the text of the CDDL should have accompanied this +.\" source. A copy of the CDDL is also available via the Internet at +.\" http://www.illumos.org/license/CDDL. +.\" +.\" +.\" Copyright (c) 2014, Joyent, Inc. All rights reserved. +.\" +.TH VND_POLLFD 3VND "Feb 21, 2014" + +.SH NAME + +vnd_pollfd \- get file descriptor for polling + +.SH SYNOPSIS + +.LP +.nf +cc [ flag... ] file... -lvnd [ library... ] +#include <libvnd.h> + +int vnd_pollfd(vnd_handle_t *vhp); +.fi + +.SH DESCRIPTION +.LP +The vnd_pollfd() function returns an integer id which corresponds to +the file descriptor that represents the underlying device that is +associated with the vnd handle vhp. This file descriptor is suitable +for use with port_associate(3C) and similar polling techniques such as +poll(2). Use of the file descriptor outside of these uses may cause +undocumented behavior from the rest of the library. + +.LP +The file descriptor in question is still managed by libvnd. The caller +must not call close(2) on it. Once vnd_close(3VND) has been called, +any further use of the file descriptor is undefined behavior. + + +.SH RETURN VALUES +.LP +The function returns the integer id of the file descriptor that +corresponds to the underlying vnd device. + +.SH EXAMPLES + +.LP +Example 1 Use event ports for vnd notifications +.sp +.LP +The following sample C program shows how to use the vnd_pollfd +function with event ports to be notified whenever there is data +available to be read. This program assumes that a vnd device named +"vnd0" exists in the current zone. For an example of creating the +device, see Example 1 in vnd_create(3VND). + +.sp +.in +2 +.nf +#include <libvnd.h> +#include <port.h> +#include <sys/types.h> +#include <unistd.h> +#include <fcntl.h> + +int +main(void) +{ + vnd_handle_t *vhp; + vnd_errno_t vnderr; + int port, syserr, vfd, ret; + + port = port_create(); + if (port < 0) { + perror("port_create"); + return (1); + } + + vhp = vnd_open(NULL, "vnd0", &vnderr, &syserr); + if (vhp == NULL) { + if (vnderr == VND_E_SYS) + (void) fprintf(stderr, "failed to open device: %s", + vnd_strsyserror(syserr)); + else + (void) fprintf(stderr, "failed to open device: %s", + vnd_strerror(vnderr)); + (void) close(port); + return (1); + } + + vfd = vnd_pollfd(vhp); + if (fcntl(vfd, F_SETFL, O_NONBLOCK) != 0) { + perror("fcntl"); + vnd_close(vhp); + (void) close(port); + return (1); + } + + if (port_associate(port, PORT_SOURCE_FD, vfd, POLLIN, NULL) != 0) { + perror("port_associate"); + vnd_close(vhp); + (void) close(port); + return (1); + } + + for (;;) { + port_event_t pe; + + + if (port_get(port, &pe, NULL) != 0) { + if (errno == EINTR) + continue; + perror("port_get"); + vnd_close(vhp); + (void) close(port); + return (1); + } + + /* + * Read the data with vnd_frameio_read(3VND) and + * optionally break out of the loop or continue to the + * next iteration and reassociate vfd with the event + * port. + */ + } +} +.fi +.in -2 + +.SH ATTRIBUTES +.sp +.LP +See attributes(5) for descriptions of the following attributes: + +.sp +.TS +box; +c | c +l | l . +ATTRIBUTE TYPE ATTRIBUTE VALUE +_ +Stability Committed +_ +MT-Level See "THREADING" in libvnd(3LIB) +.TE + +.SH SEE ALSO + +close(2), poll(2), port_create(3C), libvnd(3LIB), vnd_close(3VND) diff --git a/usr/src/man/man3vnd/vnd_prop_get.3vnd b/usr/src/man/man3vnd/vnd_prop_get.3vnd new file mode 100644 index 0000000000..e47698c85e --- /dev/null +++ b/usr/src/man/man3vnd/vnd_prop_get.3vnd @@ -0,0 +1,242 @@ +'\" te +.\" +.\" This file and its contents are supplied under the terms of the +.\" Common Development and Distribution License ("CDDL"), version 1.0. +.\" You may only use this file in accordance with the terms of version +.\" 1.0 of the CDDL. +.\" +.\" A full copy of the text of the CDDL should have accompanied this +.\" source. A copy of the CDDL is also available via the Internet at +.\" http://www.illumos.org/license/CDDL. +.\" +.\" +.\" Copyright (c) 2014, Joyent, Inc. All rights reserved. +.\" +.TH VND_PROP_GET 3VND "Feb 21, 2014" + +.SH NAME + +vnd_prop_get, vnd_prop_set \- get and set vnd properties + +.SH SYNOPSIS + +.LP +.nf +cc [ flag... ] file... -lvnd [ library... ] +#include <libvnd.h> + +int vnd_prop_get(vnd_handle_t *vhp, vnd_prop_t prop, void *buf, size_t len); + +int vnd_prop_set(vnd_handle_t *vhp, vnd_prop_t prop, void *buf, size_t len); +.fi + +.SH DESCRIPTION +.LP +The vnd_prop_get and vnd_prop_set functions are used to retrieve +and set property values on the vnd_handle_t referred to by vhp. The +property to get or set is specified by the argument prop. The +argument buf and the size of buf, in len, should be a pointer to the +appropriate structure for the property as defined in libvnd(3LIB). + +.LP +All of the supported properties are listed and described in the +libvnd(3LIB) manual page. + + +.SH RETURN VALUES +.LP +On success, the vnd_prop_get and vnd_prop_set functions return zero. +On failure, they return -1 and additional error information is +available through vnd_errno(3VND) and vnd_syserrno(3VND). + +.LP +When vnd_prop_get returns successfully, the contents of buf are +filled in with the value of the corresponding property. The contents +of buf should not change across a call to vnd_prop_set. + +.SH EXAMPLES + +.LP +Example 1 Getting the value of the rxbuf property +.LP +The following sample C program retrieves the value of the +rxbuf property and prints it to standard out. + +.sp +.in +2 +.nf +#include <libvnd.h> +#include <stdio.h> + +int +main(void) +{ + vnd_handle_t *vhp; + vnd_errno_t vnderr; + int syserr; + vnd_prop_buf_t vpb; + + vhp = vnd_open(NULL, "vnd1", &vnderr, &syserr); + if (vhp != NULL) { + if (vnderr == VND_E_SYS) + (void) fprintf(stderr, "failed to open device: %s", + vnd_strsyserror(syserr)); + else + (void) fprintf(stderr, "failed to open device: %s", + vnd_strerror(vnderr)); + return (1); + } + + if (vnd_prop_get(vhp, VND_PROP_RXBUF, &vpn, sizeof (vpn)) != 0) { + vnderr = vnd_errno(vhp); + syserr = vnd_syserrno(vhp); + if (vnderr == VND_E_SYS) + (void) fprintf(stderr, "failed to get VND_PROP_RXBUF: %s", + vnd_strsyserror(syserr)); + else + (void) fprintf(stderr, "failed to get VND_PROP_RXBUF: %s", + vnd_strerror(vnderr)); + return (1); + } + + (void) printf("recieve buffer size is %d bytes\n", vpb.vpb_size); + + vnd_close(vnd); + return (0); +} +.fi +.in -2 + +.LP +EXAMPLE 2 Setting a property +.LP +This sample C program sets the property VND_PROP_RXBUF to the value of +4200 bytes. + +.sp +.in +2 +.nf +#include <libvnd.h> +#include <stdio.h> + +int +main(void) +{ + vnd_handle_t *vhp; + vnd_errno_t vnderr; + int syserr; + vnd_prop_buf_t vpb; + + vhp = vnd_open(NULL, "vnd1", &vnderr, &syserr); + if (vhp != NULL) { + if (vnderr == VND_E_SYS) + (void) fprintf(stderr, "failed to open device: %s", + vnd_strsyserror(syserr)); + else + (void) fprintf(stderr, "failed to open device: %s", + vnd_strerror(vnderr)); + return (1); + } + + vpb.vpb_size = 4200; + if (vnd_prop_set(vhp, VND_PROP_RXBUF, &vpb, sizeof (vpb)) != 0) { + vnderr = vnd_errno(vhp); + syserr = vnd_syserrno(vhp); + if (vnderr == VND_E_SYS) + (void) fprintf(stderr, "failed to set VND_PROP_RXBUF: %s", + vnd_strsyserror(syserr)); + else + (void) fprintf(stderr, "failed to set VND_PROP_RXBUF: %s", + vnd_strerror(vnderr)); + return (1); + } + + (void) printf("successfully set VND_PROP_RXBUF to 4200\n"); + + vnd_close(vnd); + return (0); +} +.fi +.in -2 + +.LP +Example 3 Setting a property to the value of another. +.LP +In this sample C program, we set the VND_PROP_TXBUF to the maximum +allowable size as determined by the read-only property VND_PROP_MAXBUF. + +.sp +.in +2 +.nf +#include <libvnd.h> +#include <stdio.h> + +int +main(void) +{ + vnd_handle_t *vhp; + vnd_errno_t vnderr; + int syserr; + vnd_prop_buf_t vpb; + + vhp = vnd_open(NULL, "vnd1", &vnderr, &syserr); + if (vhp != NULL) { + if (vnderr == VND_E_SYS) + (void) fprintf(stderr, "failed to open device: %s", + vnd_strsyserror(syserr)); + else + (void) fprintf(stderr, "failed to open device: %s", + vnd_strerror(vnderr)); + return (1); + } + + if (vnd_prop_get(vhp, VND_PROP_MAXBUF, &vpb, sizeof (vpb)) != 0) { + vnderr = vnd_errno(vhp); + syserr = vnd_syserrno(vhp); + if (vnderr == VND_E_SYS) + (void) fprintf(stderr, "failed to get VND_PROP_MAXBUF: %s", + vnd_strsyserror(syserr)); + else + (void) fprintf(stderr, "failed to get VND_PROP_MAXBUF: %s", + vnd_strerror(vnderr)); + return (1); + } + + if (vnd_prop_set(vhp, VND_PROP_TXBUF, &vpb, sizeof (vpb)) != 0) { + vnderr = vnd_errno(vhp); + syserr = vnd_syserrno(vhp); + if (vnderr == VND_E_SYS) + (void) fprintf(stderr, "failed to set VND_PROP_TXBUF: %s", + vnd_strsyserror(syserr)); + else + (void) fprintf(stderr, "failed to set VND_PROP_TXBUF: %s", + vnd_strerror(vnderr)); + return (1); + } + + (void) printf("successfully set VND_PROP_TXBUF to %d\n", vpb.vpb_size); + + vnd_close(vnd); + return (0); +} +.fi + +.SH ATTRIBUTES +.sp +.LP +See attributes(5) for descriptions of the following attributes: + +.sp +.TS +box; +c | c +l | l . +ATTRIBUTE TYPE ATTRIBUTE VALUE +_ +Stability Committed +_ +MT-Level See "THREADING" in libvnd(3LIB) +.TE + +.SH SEE ALSO +libvnd(3VND), vnd_errno(3VND, vnd_syserrno(3VND) diff --git a/usr/src/man/man3vnd/vnd_prop_iter.3vnd b/usr/src/man/man3vnd/vnd_prop_iter.3vnd new file mode 100644 index 0000000000..29221734c5 --- /dev/null +++ b/usr/src/man/man3vnd/vnd_prop_iter.3vnd @@ -0,0 +1,148 @@ +'\" te +.\" +.\" This file and its contents are supplied under the terms of the +.\" Common Development and Distribution License ("CDDL"), version 1.0. +.\" You may only use this file in accordance with the terms of version +.\" 1.0 of the CDDL. +.\" +.\" A full copy of the text of the CDDL should have accompanied this +.\" source. A copy of the CDDL is also available via the Internet at +.\" http://www.illumos.org/license/CDDL. +.\" +.\" +.\" Copyright (c) 2014, Joyent, Inc. All rights reserved. +.\" +.TH VND_PROP_ITER 3VND "Feb 21, 2014" + +.SH NAME + +vnd_prop_iter \- iterate vnd properties + +.SH SYNOPSIS + +.LP +.nf +cc [ flag... ] file... -lvnd [ library... ] +#include <libvnd.h> + +typedef int (vnd_prop_iter_f)(vnd_handle_t *vhp, vnd_prop_t prop, + void *cbarg); + +int vnd_prop_iter(vnd_handle_t *vhp, vnd_prop_iter_f cb, + void *arg); +.fi + +.SH DESCRIPTION +.LP +The vnd_prop_iter function iterates over all the available properties +for the vnd handle vhp and calls the user supplied callback function +cb. The argument arg is passed directly to the callback function. + +.LP +The function specified by cb receives three arguments. The first, vhp, +is the same vnd library handle that was passed to vnd_prop_iter. During +the callback, the consumer should not call vnd_close(3VND). Doing so +will lead to undefined and undocumented behavior. The second argument, +prop, is the current property. While vnd_prop_iter guarantees that all +properties will be recieved, it does not guarantee the order of them. +The final argument, cbarg, is the same argument that the caller passed +in during arg. + +.LP +The return value of the callback function cb indicates whether or not +property iteration should continue. To continue iteration, the +function cb should return zero. Otherwise, to stop property iteration +it should return non-zero. + +.SH RETURN VALUES + +.LP +On success, the function vnd_prop_iter returns zero. If the callback +function returned non-zero to terminate iteration, vnd_prop_iter will +instead return one. In the case of library failure, vnd_prop_iter will +return -1. In such cases, the vnd and system errors will be updated +and available via vnd_errno(3VND) and vnd_syserrno(3VND). + +.SH EXAMPLES + +.LP +Example 1 Print writeable properties + +.LP +The following sample C program walks over every vnd property and +prints out whether the property is read-only or read-write for the +vnd device "vnd1" in the current zone. + +.sp +.in +2 +.nf +#include <libvnd.h> +#include <stdlib.h> +#include <stdio.h> + +static int +print_prop(vnd_handle_t *vhp, vnd_prop_t prop, void *unused) +{ + boolean_t canwrite; + + if (vnd_prop_writeable(vhp, &canwrite) != 0) + abort(); + + (void) printf("prop %d is %s", prop, canwrite == B_TRUE ? "rw" : "r-"); + return (0); +} + +int +main(void) +{ + vnd_handle_t *vhp; + vnd_errno_t vnderr; + int syserr; + + vhp = vnd_open(NULL, "vnd1", &vnderr, &syserr); + if (vhp != NULL) { + if (vnderr == VND_E_SYS) + (void) fprintf(stderr, "failed to open device: %s", + vnd_strsyserror(syserr)); + else + (void) fprintf(stderr, "failed to open device: %s", + vnd_strerror(vnderr)); + return (1); + } + + if (vnd_prop_iter(vhp, print_prop, NULL) != 0) { + vnderr = vnd_errno(vhp); + syserr = vnd_syserrno(vhp); + if (vnderr == VND_E_SYS) + (void) fprintf(stderr, "failed to open device: %s", + vnd_strsyserror(syserr)); + else + (void) fprintf(stderr, "failed to open device: %s", + vnd_strerror(vnderr)); + return (1); + } + + vnd_close(vnd); + return (0); +} +.fi +.in -2 + +.SH ATTRIBUTES +.sp +.LP +See attributes(5) for descriptions of the following attributes: + +.sp +.TS +box; +c | c +l | l . +ATTRIBUTE TYPE ATTRIBUTE VALUE +_ +Stability Committed +_ +MT-Level See "THREADING" in libvnd(3LIB) +.TE + +libvnd(3LIB), vnd_close(3VND), vnd_errno(3VND), vnd_syserrno(3VND) diff --git a/usr/src/man/man3vnd/vnd_prop_writeable.3vnd b/usr/src/man/man3vnd/vnd_prop_writeable.3vnd new file mode 100644 index 0000000000..c23414718b --- /dev/null +++ b/usr/src/man/man3vnd/vnd_prop_writeable.3vnd @@ -0,0 +1,101 @@ +'\" te +.\" +.\" This file and its contents are supplied under the terms of the +.\" Common Development and Distribution License ("CDDL"), version 1.0. +.\" You may only use this file in accordance with the terms of version +.\" 1.0 of the CDDL. +.\" +.\" A full copy of the text of the CDDL should have accompanied this +.\" source. A copy of the CDDL is also available via the Internet at +.\" http://www.illumos.org/license/CDDL. +.\" +.\" +.\" Copyright (c) 2014, Joyent, Inc. All rights reserved. +.\" +.TH VND_PROP_WRITEABLE 3VND "Feb 21, 2014" + +.SH NAME + +vnd_prop_writeable \- determine if a vnd property can be updated + +.SH SYNOPSIS + +.LP +.nf +cc [ flag... ] file... -lvnd [ library... ] +#include <libvnd.h> + +int vnd_prop_writeable(vnd_prop_t prop, boolean_t *wp); +.fi + + +.SH DESCRIPTION +.LP +The vnd_prop_writeable function is used as a programmatic means to +determine whether a given vnd property is writeable or not. The +property to check is specified in prop and should be from the list +described in libvnd(3VND). The argument wp is a pointer to a boolean_t +which will be updated upon the successful completion of the function. +The argument wp must be a valid pointer. If a property is writeable +than the value pointed to by wp is set to B_TRUE. If the property is +read-only, then the value is set to B_FALSE. + + +.SH RETURN VALUES +.LP +On success, vnd_prop_writeable returns zero and the value pointed to +by wp is updated with whether the property is writeable. If the +property prop does not exist, then vnd_prop_writeable will return -1. + +.SH EXAMPLES +.LP +Example 1 Check whether the property VND_PROP_TXBUF is writable +.LP +The following sample C program checks whether the vnd property +VND_PROP_TXBUF is writeable or not. + +.sp +.in +2 +.nf +#include <libvnd.h> +#include <stdio.h> +#include <stdlib.h> + +int +main(void) +{ + boolean_t canwrite; + + if (vnd_prop_writeable(VND_PROP_TXBUF, &prop) != 0) + abort(); + + if (canwrite == B_TRUE) + (void) printf("VND_PROP_TXBUF is writeable\n"); + else + (void) printf("VND_PROP_TXBUF is read only\n"); + + return (0); +} +.fi +.in -2 + +.SH ATTRIBUTES +.sp +.LP +See attributes(5) for descriptions of the following attributes: + +.sp +.TS +box; +c | c +l | l . +ATTRIBUTE TYPE ATTRIBUTE VALUE +_ +Stability Committed +_ +MT-Level MT-Safe +.TE + +.SH SEE ALSO + +vndadm(1M), libvnd(3VND) diff --git a/usr/src/man/man3vnd/vnd_walk.3vnd b/usr/src/man/man3vnd/vnd_walk.3vnd new file mode 100644 index 0000000000..bed53130d3 --- /dev/null +++ b/usr/src/man/man3vnd/vnd_walk.3vnd @@ -0,0 +1,155 @@ +'\" te +.\" +.\" This file and its contents are supplied under the terms of the +.\" Common Development and Distribution License ("CDDL"), version 1.0. +.\" You may only use this file in accordance with the terms of version +.\" 1.0 of the CDDL. +.\" +.\" A full copy of the text of the CDDL should have accompanied this +.\" source. A copy of the CDDL is also available via the Internet at +.\" http://www.illumos.org/license/CDDL. +.\" +.\" +.\" Copyright (c) 2014, Joyent, Inc. All rights reserved. +.\" +.TH VND_CREATE 3VND "Feb 21, 2014" + +.SH NAME + +vnd_walk \- walk all vnd devices + + +.SH SYNOPSIS + +.LP +.nf +cc [ flag... ] file... -lvnd [ library... ] +#include <libvnd.h> + +typedef int (*vnd_walk_cb_f)(vnd_info_t *viip, void *cbarg); + +int vnd_walk(vnd_walk_cb_t cb, void *arg, vnd_errno_t *vnderr, int *syserr); +.fi + + +.SH DESCRIPTION +.LP +The vnd_walk() function fires the callback function cb once for every +vnd device that is visible in the current zone. If the caller is in +the global zone, then all vnd devices in all zones will be walked. If +the caller is in a non-global zone, then only the devices in that zone +will be visible. + +.LP +The function cb will be called with two arguments. The first argument, +viip, is a pointer to a structure that contains information about the +link. The second argument to the function cb, cbarg, is the same +argument that is passed to the function vnd_walk as arg. To continue +the function cb should return zero. If the function cb returns +non-zero the walk will terminate. + +.LP +As the vnd_walk function does not have a handle, errors are returned +in vnderr and syserr. Both vnderr and syserr are allowed to be NULL +pointers. If either one is a NULL pointer, then error information for +that class of error will not be returned. It is not recommended that +consumers supply NULL pointers. + +.LP +The vnd_info_t structure contains the following members: + +.in +2 +.nf +uint32_t vi_version +zoneid_t vi_zone +char vi_name[LIBVND_NAMELEN]; +char vi_datalink[LIBVND_NAMELEN]; +.fi +.in -2 + +.LP +The member vi_version is guaranteed to be the first member of the +structure. This number indicates the current revision of the structure +and is set to the integer value 1. More properties may be added in +future releases. Those properties will be tied to a greater version +number so software knows whether or not it is legal to access them. + +.LP +The vi_zone field indicates the zone id that the vnd device exists in. +The vi_name field is the name of the vnd device. If the vnd_device is +not linked, the name field is set to "<unknown>". The vi_datalink +field is filled in with the name of the data link the vnd device is on +top of. + + +.SH RETURN VALUES + +.LP +The vnd_walk function will return zero on success. If the consumer +supplied callback function returned non-zero, then the vnd_walk +function will return 1. If an error occurred, -1 is returned, and if +vnderr and syserr are non-null, they are filled in with their +respective error values. See vnd_errno(3VND) for more information on +these errors. + +.SH EXAMPLES + +.LP +Example 1 Walk all devices and print information about them + +.LP +The following sample C program walks every vnd device and prints out +information about them. + +.sp +.in +2 +.nf +#include <libvnd.h> +#include <stdio.h> + +static int +print_entry(vnd_info_t *viip, void *unused) +{ + (void) printf("device %s over data link %s in zone %d\n", + viip->vi_name, viip->vi_datalink, viip->vi_zone); + return (0); +} + +int +main(void) +{ + vnd_errno_t vnderr; + int syserr; + + if (vnd_walk(print_entry, NULL, &vnderr, &syserr) != 0) { + (void) fprintf(stderr, "failed to walk vnd devices: %s\n", + vnderr != VND_E_SYS ? vnd_strerror(vnderr) : + vnd_strsyserror(syserr)); + return (1); + } + + return (0); +} +.fi +.in -2 + +.SH ATTRIBUTES +.sp +.LP +See attributes(5) for descriptions of the following attributes: + +.sp +.TS +box; +c | c +l | l . +ATTRIBUTE TYPE ATTRIBUTE VALUE +_ +Stability Committed +_ +MT-Level MT-Safe +.TE + +.SH SEE ALSO + +libvnd(3VND), vnd_errno(3VND), attributes(5), zones(5) |