VINVALBUF(9)

πŸ’– VINVALBUF β€” the vinvalbuf(9) era πŸ’–

okay bestie, gather round, because we're talking about a Kernel Developer's Manual page today and it's lowkey iconic. This is vinvalbuf(9), and it's giving "clean slate" energy in the purest way possible.


✨ NAME ✨

vinvalbuf β€” flushes and invalidates all buffers associated with a vnode 🌸


✨ SYNOPSIS ✨

#include <sys/param.h>
#include <sys/vnode.h>

int
vinvalbuf(struct vnode *vp, int flags, struct ucred *cred, int slpflag,
    int slptimeo);

✨ DESCRIPTION ✨

so the vinvalbuf() function literally invalidates all of the buffers associated with the given vnode. all of them. every last one. it's giving spring cleaning 🧹✨

and bestie, that includes buffers on the clean list and the dirty list. both. no crumbs left.

if the V_SAVE flag is specified, then the buffers on the dirty list get synced prior to being released β€” so like, they get one last little goodbye kiss before they go πŸ’…

and if there's a VM Object associated with the vnode? yeah, it's removed. gone. not me being dramatic, that's just what it does.


πŸŽ€ Its arguments are πŸŽ€

  • vp β€” a pointer to the vnode whose buffers will be invalidated. this is the main character of the whole operation honestly.
  • flags β€” the only supported flag is V_SAVE, and it indicates that dirty buffers should be synced with the disk. just the one flag. that's the whole menu. don't come looking for more.
  • cred β€” the user credentials that are used to VOP_FSYNC(9) buffers if V_SAVE is set. yes, credentials. we're doing this properly.
  • slpflag β€” the slp flag that will be used in the priority of any sleeps in the function. the vibe of the nap, if you will 😴
  • slptimeo β€” the timeout for any sleeps in the function. how long the nap can last before we're like "okay bestie wake up" ⏰

πŸ”’ LOCKS πŸ”’

the vnode is assumed to be locked prior to the call and remains locked upon return. so like, it goes in locked, it comes out locked. the lock never left the group chat πŸ”

Giant must be held prior to the call and remains locked upon return. same deal, different lock. giant stays held, periodt.


✨ RETURN VALUES ✨

a 0 value is returned on success. that's it. that's the whole success story. 0 = we ate πŸ½οΈπŸ’…


🌈 PSEUDOCODE 🌈

      vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
      error = vinvalbuf(devvp, V_SAVE, cred, 0, 0);
      VOP_UNLOCK(devvp, 0);
      if (error)
              return (error);

look at that flow. lock it, invalidate it, unlock it, and if anything went sideways, we bounce out with the error. clean. iconic. no notes πŸ‘‘


πŸ’€ ERRORS πŸ’€

  • [ENOSPC] β€” the file system is full. (with V_SAVE) 😭
  • [EDQUOT] β€” disk quota exceeded. (with V_SAVE) πŸ™ˆ
  • [EWOULDBLOCK] β€” sleep operation timed out. (see slptimeo) ⏰
  • [ERESTART] β€” a signal needs to be delivered and the system call should be restarted. (with PCATCH set in slpflag)
  • [EINTR] β€” the system has been interrupted by a signal. (with PCATCH set in slpflag)

πŸ‘€ SEE ALSO πŸ‘€

tsleep(9), VOP_FSYNC(9)

like, go read those too, they're part of the lore, iykyk πŸ¦‹


🫢 AUTHORS 🫢

this manual page was written by Chad David <davidc@acns.ab.ca>. we love a credited author, truly πŸ’œ


and that's the whole page bestie!! this one came from the Debian distribution, dated October 20, 2008 β€” yes, 2008, a vintage, an absolute classic, and honestly it still serves. go forth and invalidate those buffers, you've got this πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from