aboutsummaryrefslogtreecommitdiff
path: root/sys/sys/sbuf.h
Commit message (Collapse)AuthorAgeFilesLines
* Export sbuf_drain to orchestrate lock and drain actionRichard Scheffenegger2021-03-311-0/+1
| | | | | | | | | | | | | | | While exporting large amounts of data to a sysctl request, datastructures may need to be locked. Exporting the sbuf_drain function allows the coordination between drain events and held locks, to avoid stalls. PR: 254333 Reviewed By: jhb MFC after: 2 weeks Sponsored by: NetApp, Inc. Differential Revision: https://reviews.freebsd.org/D29481
* sbuf(9): Add sbuf_nl_terminate() APIConrad Meyer2019-08-071-0/+2
| | | | | | | | | | | | | | The API is used to gracefully terminate text line(s) with a single \n. If the formatted buffer was empty or already ended in \n, it is unmodified. Otherwise, a newline character is appended to it. The API, like other sbuf-modifying routines, is only valid while the sbuf is not FINISHED. Reviewed by: rlibby Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D21030 Notes: svn path=/head/; revision=350693
* sbuf(9): Add NOWAIT dynamic buffer extension modeConrad Meyer2019-08-071-0/+1
| | | | | | | | | | | | The goal is to avoid some kinds of low-memory deadlock when formatting heap-allocated buffers. Reviewed by: vangyzen Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D21015 Notes: svn path=/head/; revision=350691
* Optimize kern.geom.conf* sysctls.Alexander Motin2019-06-181-0/+1
| | | | | | | | | | | | | | | | | | | | | On large systems those sysctls may generate megabytes of output. Before this change sbuf(9) code was resizing buffer by 4KB each time many times, generating tons of TLB shootdowns. Unfortunately in this case existing sbuf_new_for_sysctl() mechanism, supposed to help with this issue, is not applicable, since all the sbuf writes are done in different kernel thread. This change improves situation in two ways: - on first sysctl call, not providing any output buffer, it sets special sbuf drain function, just counting the data and so not needing big buffer; - on second sysctl call it uses as initial buffer size value saved on previous call, so that in most cases there will be no reallocation, unless GEOM topology changed significantly. MFC after: 1 week Sponsored by: iXsystems, Inc. Notes: svn path=/head/; revision=349178
* device_printf: Use sbuf for more coherent prints on SMPConrad Meyer2019-05-071-0/+1
| | | | | | | | | | | | | | | | | device_printf does multiple calls to printf allowing other console messages to be inserted between the device name, and the rest of the message. This change uses sbuf to compose to two into a single buffer, and prints it all at once. It exposes an sbuf drain function (drain-to-printf) for common use. Update documentation to match; some unit tests included. Submitted by: jmg Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D16690 Notes: svn path=/head/; revision=347229
* sys/sys: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-271-0/+2
| | | | | | | | | | | | | | | Mainly focus on files that use BSD 2-Clause license, however the tool I was using misidentified many licenses so this was mostly a manual - error prone - task. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Notes: svn path=/head/; revision=326256
* Implement simple record boundary tracking in sbuf(9) to avoid record splittingLawrence Stewart2017-08-171-0/+2
| | | | | | | | | | | | | | | during drain operations. When an sbuf is configured to use this feature by way of the SBUF_DRAINTOEOR sbuf_new() flag, top-level sections started with sbuf_start_section() create a record boundary marker that is used to avoid flushing partial records. Reviewed by: cem,imp,wblock MFC after: 2 weeks Sponsored by: Netflix, Inc. Differential Revision: https://reviews.freebsd.org/D8536 Notes: svn path=/head/; revision=322614
* Add prototype for sbuf_putbuf()Scott Long2017-02-281-0/+1
| | | | | | | Sponsored by: Netflix Notes: svn path=/head/; revision=314399
* Add support for reading MAM attributes to camcontrol(8) and libcam(3).Kenneth D. Merry2015-06-091-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | MAM is Medium Auxiliary Memory and is most commonly found as flash chips on tapes. This includes support for reading attributes and decoding most known attributes, but does not yet include support for writing attributes or reporting attributes in XML format. libsbuf/Makefile: Add subr_prf.c for the new sbuf_hexdump() function. This function is essentially the same function. libsbuf/Symbol.map: Add a new shared library minor version, and include the sbuf_hexdump() function. libsbuf/Version.def: Add version 1.4 of the libsbuf library. libutil/hexdump.3: Document sbuf_hexdump() alongside hexdump(3), since it is essentially the same function. camcontrol/Makefile: Add attrib.c. camcontrol/attrib.c: Implementation of READ ATTRIBUTE support for camcontrol(8). camcontrol/camcontrol.8: Document the new 'camcontrol attrib' subcommand. camcontrol/camcontrol.c: Add the new 'camcontrol attrib' subcommand. camcontrol/camcontrol.h: Add a function prototype for scsiattrib(). share/man/man9/sbuf.9: Document the existence of sbuf_hexdump() and point users to the hexdump(3) man page for more details. sys/cam/scsi/scsi_all.c: Add a table of known attributes, text descriptions and handler functions. Add a new scsi_attrib_sbuf() function along with a number of other related functions that help decode attributes. scsi_attrib_ascii_sbuf() decodes ASCII format attributes. scsi_attrib_int_sbuf() decodes binary format attributes, and will pass them off to scsi_attrib_hexdump_sbuf() if they're bigger than 8 bytes. scsi_attrib_vendser_sbuf() decodes the vendor and drive serial number attribute. scsi_attrib_volcoh_sbuf() decodes the Volume Coherency Information attribute that LTFS writes out. sys/cam/scsi/scsi_all.h: Add a number of attribute-related structure definitions and other defines. Add function prototypes for all of the functions added in scsi_all.c. sys/kern/subr_prf.c: Add a new function, sbuf_hexdump(). This is the same as the existing hexdump(9) function, except that it puts the result in an sbuf. This also changes subr_prf.c so that it can be compiled in userland for includsion in libsbuf. We should work to change this so that the kernel hexdump implementation is a wrapper around sbuf_hexdump() with a statically allocated sbuf with a drain. That will require a drain function that goes to the kernel printf() buffer that can take a non-NUL terminated string as input. That is because an sbuf isn't NUL-terminated until it is finished, and we don't want to finish it while we're still using it. We should also work to consolidate the userland hexdump and kernel hexdump implemenatations, which are currently separate. This would also mean making applications that currently link in libutil link in libsbuf. sys/sys/sbuf.h: Add the prototype for sbuf_hexdump(), and add another copy of the hexdump flag values if they aren't already defined. Ideally the flags should be defined in one place but the implemenation makes it difficult to do properly. (See above.) Sponsored by: Spectra Logic Corporation MFC after: 1 week Notes: svn path=/head/; revision=284192
* Add a new flag, SBUF_INCLUDENUL, and new get/set/clear functions for flags.Ian Lepore2015-03-141-0/+4
| | | | | | | | | | | The SBUF_INCLUDENUL flag causes the nulterm byte at the end of the string to be counted in the length of the data. If copying the data using the sbuf_data() and sbuf_len() functions, or if writing it automatically with a drain function, the net effect is that the nulterm byte is copied along with the rest of the data. Notes: svn path=/head/; revision=279992
* Unbreak the ABI by reverting r268494 until the compat shims are providedPietro Cerutti2014-07-281-6/+3
| | | | Notes: svn path=/head/; revision=269179
* Implement Short/Small String Optimization in SBUF(9) and change lengths andPietro Cerutti2014-07-101-3/+6
| | | | | | | | | | positions in the API from ssize_t and int to size_t. CR: D388 Approved by: des, bapt Notes: svn path=/head/; revision=268494
* Add sbuf_start_section() and sbuf_end_section() functions, which canMikolaj Golub2013-04-111-0/+4
| | | | | | | | | | | be used for automatic section alignment. Discussed with: kib Reviewed by: kib MFC after: 1 month Notes: svn path=/head/; revision=249377
* Change the length quantities of sbufs to be ssize_t rather than int.Poul-Henning Kamp2011-05-161-6/+6
| | | | | | | Constify a couple of arguments. Notes: svn path=/head/; revision=221993
* Replace sbuf_overflowed() with sbuf_error(), which returns any errorMatthew D Fleming2010-09-101-2/+1
| | | | | | | | | code associated with overflow or with the drain function. While this function is not expected to be used often, it produces more information in the form of an errno that sbuf_overflowed() did. Notes: svn path=/head/; revision=212425
* Add drain functionality to sbufs. The drain is a function that isMatthew D Fleming2010-09-091-2/+8
| | | | | | | | | | | | | | | | | | | | called when the sbuf internal buffer is filled. For kernel sbufs with a drain, the internal buffer will never be expanded. For userland sbufs with a drain, the internal buffer may still be expanded by sbuf_[v]printf(3). Sbufs now have three basic uses: 1) static string manipulation. Overflow is marked. 2) dynamic string manipulation. Overflow triggers string growth. 3) drained string manipulation. Overflow triggers draining. In all cases the manipulation is 'safe' in that overflow is detected and managed. Reviewed by: phk (the previous version) Notes: svn path=/head/; revision=212367
* Add sbuf_new_auto as a shortcut for the very common case of creating aDag-Erling Smørgrav2008-08-091-0/+2
| | | | | | | | | | completely dynamic sbuf. Obtained from: Varnish MFC after: 2 weeks Notes: svn path=/head/; revision=181463
* Switch to simplified BSD license (with phk's approval), plus whitespaceDag-Erling Smørgrav2008-08-091-16/+18
| | | | | | | and style(9) cleanup. Notes: svn path=/head/; revision=181462
* Have sbuf_bcat() and sbuf_bcpy() take a const void * instead of aDag-Erling Smørgrav2004-07-091-2/+2
| | | | | | | | const char *, since callers are likely to pass in pointers to all kinds of structs and whatnot. Notes: svn path=/head/; revision=131868
* Add the new function "sbuf_done()" which returns non-zero if the sbuf isPoul-Henning Kamp2002-10-041-0/+1
| | | | | | | | | | | | finished. This allows sbufs to be used for request/response scenarioes without needing additional communication flags. Sponsored by: DARPA & NAI Labs. Notes: svn path=/head/; revision=104449
* o Merge <machine/ansi.h> and <machine/types.h> into a new headerMike Barcroft2002-08-211-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | called <machine/_types.h>. o <machine/ansi.h> will continue to live so it can define MD clock macros, which are only MD because of gratuitous differences between architectures. o Change all headers to make use of this. This mainly involves changing: #ifdef _BSD_FOO_T_ typedef _BSD_FOO_T_ foo_t; #undef _BSD_FOO_T_ #endif to: #ifndef _FOO_T_DECLARED typedef __foo_t foo_t; #define _FOO_T_DECLARED #endif Concept by: bde Reviewed by: jake, obrien Notes: svn path=/head/; revision=102227
* Replace spaces after #defines with tabs; this makes all #definesKelly Yancey2002-01-091-6/+6
| | | | | | | consistent in their adherence with style(9). Notes: svn path=/head/; revision=89121
* * Implement SBUF_AUTOEXTEND flag; sbufs created with this flag areKelly Yancey2002-01-061-1/+6
| | | | | | | | | | | | | automatically extended to prevent overflow. * Added sbuf_vprintf(); sbuf_printf() is now just a wrapper around sbuf_vprintf(). * Include <stdio.h> and <string.h> when building libsbuf to silence WARNS=4 warnings. Reviewed by: des Notes: svn path=/head/; revision=88950
* Reduce namespace pollution by removing argument names from prototypes.Dag-Erling Smørgrav2001-12-041-18/+18
| | | | Notes: svn path=/head/; revision=87318
* Add a couple of API functions I need for my pseudofs WIP. DocumentationDag-Erling Smørgrav2001-09-291-0/+3
| | | | | | | | will follow when I've decided whether to keep this API or ditch it in favor of something slightly more subtle. Notes: svn path=/head/; revision=84097
* Add printf format checking to sbuf_printf()Poul-Henning Kamp2001-07-181-1/+1
| | | | | | | Submitted by: Harti Brandt <brandt@fokus.gmd.de Notes: svn path=/head/; revision=79870
* Constify the format string.Dag-Erling Smørgrav2001-07-031-1/+1
| | | | | | | Submitted by: Mike Barcroft <mike@q9media.com> Notes: svn path=/head/; revision=79162
* Add sbuf_copyin(). Also add 'b' variants of sbuf_{cat,copyin,cpy}() whichDag-Erling Smørgrav2001-06-111-0/+7
| | | | | | | ignore NUL bytes in the source string. Notes: svn path=/head/; revision=78077
* sbuf_new(9) now returns a struct sbuf * instead of an int. If the callerDag-Erling Smørgrav2001-06-101-12/+13
| | | | | | | | does not provide a struct sbuf, sbuf_new(9) will allocate one and return a pointer to it. Notes: svn path=/head/; revision=77989
* Rewrite of the CAM error recovery code.Kenneth D. Merry2001-03-271-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Some of the major changes include: - The SCSI error handling portion of cam_periph_error() has been broken out into a number of subfunctions to better modularize the code that handles the hierarchy of SCSI errors. As a result, the code is now much easier to read. - String handling and error printing has been significantly revamped. We now use sbufs to do string formatting instead of using printfs (for the kernel) and snprintf/strncat (for userland) as before. There is a new catchall error printing routine, cam_error_print() and its string-based counterpart, cam_error_string() that allow the kernel and userland applications to pass in a CCB and have errors printed out properly, whether or not they're SCSI errors. Among other things, this helped eliminate a fair amount of duplicate code in camcontrol. We now print out more information than before, including the CAM status and SCSI status and the error recovery action taken to remedy the problem. - sbufs are now available in userland, via libsbuf. This change was necessary since most of the error printing code is shared between libcam and the kernel. - A new transfer settings interface is included in this checkin. This code is #ifdef'ed out, and is primarily intended to aid discussion with HBA driver authors on the final form the interface should take. There is example code in the ahc(4) driver that implements the HBA driver side of the new interface. The new transfer settings code won't be enabled until we're ready to switch all HBA drivers over to the new interface. src/Makefile.inc1, lib/Makefile: Add libsbuf. It must be built before libcam, since libcam uses sbuf routines. libcam/Makefile: libcam now depends on libsbuf. libsbuf/Makefile: Add a makefile for libsbuf. This pulls in the sbuf sources from sys/kern. bsd.libnames.mk: Add LIBSBUF. camcontrol/Makefile: Add -lsbuf. Since camcontrol is statically linked, we can't depend on the dynamic linker to pull in libsbuf. camcontrol.c: Use cam_error_print() instead of checking for CAM_SCSI_STATUS_ERROR on every failed CCB. sbuf.9: Change the prototypes for sbuf_cat() and sbuf_cpy() so that the source string is now a const char *. This is more in line wth the standard system string functions, and helps eliminate warnings when dealing with a const source buffer. Fix a typo. cam.c: Add description strings for the various CAM error status values, as well as routines to look up those strings. Add new cam_error_string() and cam_error_print() routines for userland and the kernel. cam.h: Add a new CAM flag, CAM_RETRY_SELTO. Add enumerated types for the various options available with cam_error_print() and cam_error_string(). cam_ccb.h: Add new transfer negotiation structures/types. Change inq_len in the ccb_getdev structure to be "reserved". This field has never been filled in, and will be removed when we next bump the CAM version. cam_debug.h: Fix typo. cam_periph.c: Modularize cam_periph_error(). The SCSI error handling part of cam_periph_error() is now in camperiphscsistatuserror() and camperiphscsisenseerror(). In cam_periph_lock(), increase the reference count on the periph while we wait for our lock attempt to succeed so that the periph won't go away while we're sleeping. cam_xpt.c: Add new transfer negotiation code. (ifdefed out) Add a new function, xpt_path_string(). This is a string/sbuf analog to xpt_print_path(). scsi_all.c: Revamp string handing and error printing code. We now use sbufs for much of the string formatting code. More of that code is shared between userland the kernel. scsi_all.h: Get rid of SS_TURSTART, it wasn't terribly useful in the first place. Add a new error action, SS_REQSENSE. (Send a request sense and then retry the command.) This is useful when the controller hasn't performed autosense for some reason. Change the default actions around a bit. scsi_cd.c, scsi_da.c, scsi_pt.c, scsi_ses.c: SF_RETRY_SELTO -> CAM_RETRY_SELTO. Selection timeouts shouldn't be covered by a sense flag. scsi_pass.[ch]: SF_RETRY_SELTO -> CAM_RETRY_SELTO. Get rid of the last vestiges of a read/write interface. libkern/bsearch.c, sys/libkern.h, conf/files: Add bsearch.c, which is needed for some of the new table lookup routines. aic7xxx_freebsd.c: Define AHC_NEW_TRAN_SETTINGS if CAM_NEW_TRAN_CODE is defined. sbuf.h, subr_sbuf.c: Add the appropriate #ifdefs so sbufs can compile and run in userland. Change sbuf_printf() to use vsnprintf() instead of kvprintf(), which is only available in the kernel. Change the source string for sbuf_cpy() and sbuf_cat() to be a const char *. Add __BEGIN_DECLS and __END_DECLS around function prototypes since they're now exported to userland. kdump/mkioctls: Include stdio.h before cam.h since cam.h now includes a function with a FILE * argument. Submitted by: gibbs (mostly) Reviewed by: jdp, marcel (libsbuf makefile changes) Reviewed by: des (sbuf changes) Reviewed by: ken Notes: svn path=/head/; revision=74840
* Add sbuf_clear() and sbuf_overflowed().Dag-Erling Smørgrav2001-01-281-19/+8
| | | | | | | | | | | | | Move the helper macros from sbuf.h to sbuf.c Use ints instead of size_ts. Relax the requirements for sbuf_finish(): it is now possible to finish an overflowed buffer. Make sbuf_len() return -1 instead of 0 if the sbuf overflowed. Requested by: gibbs Notes: svn path=/head/; revision=71721
* String buffer APIDag-Erling Smørgrav2000-12-131-0/+76
Notes: svn path=/head/; revision=69990