PMEM2_SOURCE_DEVICE_USC(3)

πŸ’– pmem2_source_device_usc() πŸ’–

okay bestie, so this one lives in the PMDK Programmer's Manual (yes, that PMDK, the persistent memory one, we're fancy now ✨) and it's literally the little function that tells you how many times your hardware got caught lacking during an unsafe shutdown. no cap.


✨ NAME ✨

pmem2_source_device_usc() β€” returns the unsafe shutdown counter value of a device 🫢


🌸 SYNOPSIS 🌸

#include <libpmem2.h>

struct pmem2_source;
int pmem2_source_device_usc(const struct pmem2_source *source, uint64_t *usc);

πŸ¦‹ DESCRIPTION πŸ¦‹

so the way that pmem2_source_device_usc() works is: it goes and grabs the sum of the unsafe shutdown count (USC) values of all hardware devices backing the data source, and then it drops that number into *usc. like, it's collecting receipts from every single device involved and adding them all up πŸ’…

and listen β€” this is important β€” you can't just run around using this number however you feel. please refer to libpmem2_unsafe_shutdown(7) for the detailed description on how to properly consume this information. it's giving "read the instructions before you touch the thing", fr fr. πŸ™ˆ


πŸ‘‘ RETURN VALUE πŸ‘‘

pmem2_source_device_usc() returns 0 on success. iconic. ✨

but if the function fails? then the content of the *usc variable is left unmodified (it does not get half-written, it does not get a vibe check, it stays exactly how you left it) and a negative error code is returned instead. 😭


πŸ’€ ERRORS πŸ’€

pmem2_source_device_usc() can fail with the following errors:

  • PMEM2_E_NOSUPP β€” the underlying platform does not expose unsafe shutdown count information. so like, the info literally does not exist here, bestie, nothing we can do πŸ’”
  • -errno set by failing fstat(2), while trying to validate the file descriptor.
  • -errno set by failing ndctl_new(), while trying to initiate a new NDCTL library context.
  • -errno set by failing ndctl_dimm_get_dirty_shutdown(), while trying to obtain DIMM USC value.
bestie if you see any of those -errno ones, that means the underlying call flopped and the error number got handed straight back to you. go check errno(3), iykyk πŸŽ€

🌈 SEE ALSO 🌈

fstat(2), errno(3), malloc(3), libpmem2_unsafe_shutdown(7), and https://pmem.io πŸ”₯


okay that's the whole page, mwah πŸ’œ this was the PMDK version, dated 2025-07-24 β€” go forth and check your unsafe shutdown counters responsibly, queen πŸ‘‘πŸ’…

πŸ“¦ where this page comes from