LLAPI_IOCTL(3)

πŸ“¦ version 2.17.58, in ubuntu stonking

πŸ’– LLAPI_IOCTL β€” bestie edition πŸ’–

okay so this is a page from the Lustre Library Functions corner of the manual, section 3 (the library-functions section, iykyk). Sit down, grab a boba, we're learning llapi_ioctl 🫢


✨ NAME ✨

llapi_ioctl β€” call ioctl() but with possible command remapping πŸ’…


✨ SYNOPSIS ✨

#include <lustre/lustreapi.h>

int llapi_ioctl(int fd, unsigned int cmd, void *buf);

✨ DESCRIPTION ✨

So here's the tea β˜• β€” llapi_ioctl() calls the ioctl(2) system call with the arguments you hand it. Simple, right? But there's a lil plot twist πŸ‘€

If ioctl() comes back with ENOTTY (that's the "no such ioctl" vibe), then if cmd has been remapped from an older ioctl command number, the ioctl() call gets retried using that old ioctl command number. So it's like, "sorry bestie, try the legacy one" and it does πŸ”βœ¨


✨ RETURN VALUES ✨

llapi_ioctl() typically returns:

  • 0 β€” on success, in most cases πŸŽ‰
  • <0 β€” a negative value on failure, and it sets errno. And ngl, because ioctl commands are so varied, it may return different values and errno as appropriate for the fd, the cmd number, and the buf argument you passed in. No single fixed answer, it's giving "depends" πŸ’€

✨ EXAMPLES ✨

here's the whole thing, verbatim, no edits, main character energy:

#include <lustre/lustreapi.h>

int main(int argc, char *argv[])
{
    unsigned long group = 1234;
    int rc, fd;

    fd = open(argv[1], O_RDONLY);
    if (rc < 0) {
        fprintf(stderr, "error opening file '%s': %s\n",
            argv[1], strerror(errno));
        return -1;
    }

    rc = llapi_ioctl(fd, LL_IOC_GROUP_LOCK, &group);
    if (rc < 0) {
        fprintf(stderr, "%s: ioctl error: %s\n",
            argv[1], strerror(errno));
        return rc;
    }

    printf("%s: locked with group %lu\n", argv[1], group);
    return 0;
}

✨ AVAILABILITY ✨

llapi_ioctl() has been part of the lustre(7) user application interface library since release 2.16.0 🌈 so if you're on anything older, sorry babe, you don't got it yet πŸ™ˆ


✨ SEE ALSO ✨


reminder bestie: keep every cmd, fd, buf and errno exactly as-is when you write your own code. The remapping is real, the vibes are immaculate, but the flags are the flags πŸ’…

and that's the whole page, no crumbs left πŸ“ this was Lustre User API, dated 2024-08-27, and yes she ate πŸ‘‘βœ¨ mwah, go forth and ioctl responsibly πŸ’–

πŸ“¦ where this page comes from