Date: Tue, 7 Sep 2010 11:12:55 -0700 From: mdf@FreeBSD.org To: FreeBSD Arch <freebsd-arch@freebsd.org> Subject: Extending sbufs with a drain Message-ID: <AANLkTinReHpgm8Bt8ya=PY-3Mz6w0FwcGq-psrjiesKv@mail.gmail.com>
next in thread | raw e-mail | index | archive | help
Isilon developed a formatted print system basically in parallel with FreeBSD's sbuf code. One of the things isi_format has that sbuf is lacking is the comcept of a drain. Basically a drain is a way to limit the size of the sbuf and, instead of reallocating the buffer when it is full, the contents are flushed under the control of a callback to "elsewhere". The common drains used at Isilon are to flush to log(9), printf(9), and SYSCTL_OUT(9). One of the advantages to using drains is that formatted print functions don't need to know where the data is going; they just always print to an sbuf and let the caller of the formatted print function know what he intended with the data. The first two patches simplify the sbuf(9) code a little. http://people.freebsd.org/~mdf/0001-Replace-the-SBUF_OVERFLOWED-flag-with-an-s_error-cod.patch http://people.freebsd.org/~mdf/0002-Compare-SBUF_FREESPACE-against-0-instead-of-using-th.patch This is the main patch, which uses the drain functionality to extend sbufs (unless the drain is overridden), and also creates an initializer for draining to a sysctl_req. The man page changes are included in this patch. http://people.freebsd.org/~mdf/0003-Add-drain-functionality-to-sbufs.-The-drain-is-a-fun.patch I would like to commit this work later this week. One possibility to allow MFC is to package the drain variables (function pointer, argument, error code storage) into an sbuf_drain struct and use the s_unused field to point to a caller-supplied storage for the drain data. I didn't go this way since it seemed more awkward long term. There is a need for regression suite against libsbuf. I looked at the existing tests for libutil to try to understand it but the syntax of expected results was beyond my comprehension at this time. Questions? Comments? Bug reports? As I indicate in a comment in sbuf.h, it seems that the buffered printf(2) functionality could be implemented using sbufs as the buffer and different drains depending on which kind of printf is wanted: one drain to a string buffer ala sprintf, one to a FILE* ala fprintf, etc. This seems cleaner than the existing FAKE_FILE hack to get fprintf(2) to print to a string. However, the printf(2) code was also rather obtuse and I haven't had time to untangle it yet. Thanks, matthew
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?AANLkTinReHpgm8Bt8ya=PY-3Mz6w0FwcGq-psrjiesKv>