nbd_trim(3)
π nbd_trim(3) β the libnbd girlies' guide
okay so bestie, welcome to the nbd_trim(3) manual page from LIBNBD. yes it's a C function. no you're not gonna be scared of it. let's go π
β¨ NAME β¨
nbd_trim β send a trim command to the NBD server. that's it, that's the vibe. you're telling the server "hey, delete this chunk for me" and the server either gets it or it doesn't π
πΈ SYNOPSIS πΈ
#include <libnbd.h>
int nbd_trim (
struct nbd_handle *h, uint64_t count,
uint64_t offset, uint32_t flags
);
look at that signature. four args. h is your handle, count is the size, offset is where, flags is the extras. she's neat, she's tidy, she's giving main character energy π₯
π¦ DESCRIPTION π¦
so what actually happens: you issue a trim command to the NBD server, and if the server supports it, it punches a hole in the backing store β starting at offset and ending at offset + count - 1. like literally carving out a chunk. iconic honestly β¨
the call returns when the server has acknowledged the command, or when there's an error. not before, not after, she waits her turn π«Ά
heads up bestie: this will generally return an error ifnbd_can_trim(3)is false, or ifnbd_is_read_only(3)is true. like duh, you can't trim a read-only thing. be so serious rn π
also β and this is the part everyone forgets β not all servers can support a count of 4GiB or larger. nbd_get_extended_headers_negotiated(3) is your bestie here: it tells you which servers will actually parse a request bigger than 32 bits. the NBD protocol does not yet have a way for a client to learn if the server will enforce an even smaller maximum trim size β although a future extension may add a constraint visible in nbd_get_block_size(3). so like. watch this space β¨
about flags
the flags parameter may be 0 for no flags, or it may contain LIBNBD_CMD_FLAG_FUA β which means the server shouldn't return until the data has been committed to permanent storage. but only if that is supported β some servers literally cannot do this, check nbd_can_fua(3) first, i'm begging π
π RETURN VALUE π
if the call is successful, the function returns 0. slay. that's the good ending π
π₯ ERRORS π₯
on error, -1 is returned. that's the not-so-girlboss ending π
refer to "ERROR HANDLING" in libnbd(3) for how to get further details of the error. the lore is all in there, iykyk.
also: the following parameters must not be NULL: h. do not pass NULL. i'm not asking. for more info see "Non-NULL parameters" in libnbd(3) π«Ά
β NOTES β
Strict call
by default, libnbd will reject attempts to use this function with parameters that are likely to result in server failure β like requesting an unknown command flag. rude? maybe. sensible? yes bestie π
the nbd_set_strict_mode(3) function can be used to alter which scenarios should await a server reply rather than failing fast. so if you want to be chaotic and hear the server out, that's your girl.
π HANDLE STATE π
nbd_trim can be called when the handle is in the following state:
- Handle created, before connecting β β error
- Connecting β β error
- Connecting & handshaking (
opt_mode) β β error - Connected to the server β β allowed
- Connection shut down β β error
- Handle dead β β error
so basically: connect first. there's exactly one green check and it's the one where you're actually connected. the way that every other row is just no π
π VERSION π
this function first appeared in libnbd 1.0. a legend from the beginning, no cap π
if you need to test if this function is available at compile time, check if the following macro is defined:
#define LIBNBD_HAVE_NBD_TRIM 1
π SEE ALSO π
nbd_aio_trim(3), nbd_can_fua(3), nbd_can_trim(3), nbd_create(3), nbd_get_block_size(3), nbd_get_extended_headers_negotiated(3), nbd_is_read_only(3), nbd_set_strict_mode(3), libnbd(3).
the whole friend group, fr fr π«Ά
π AUTHORS π
- Eric Blake
- Richard W.M. Jones
the actual masterminds behind this. respect the architects π
π§ COPYRIGHT π§
Copyright Red Hat
π LICENSE π
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
okay that's the whole page bestie, you ate that π
this was libnbd-1.25.8, dated 2026-10-13, and she's filed under nbd_trim(3). go punch some holes in a backing store responsibly πΈβ¨
π¦ where this page comes from
- centos-stream 10: libnbd-devel 1.25.8-1.el10 Β· LGPL-2.0-or-later AND BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms