From: Lennart Poettering Date: Mon, 6 Mar 2023 11:06:21 +0000 (+0100) Subject: loop-util: keep track of inode/devnum of backing file X-Git-Tag: v254-rc1~1072^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4d2a9e3ea6f1dbfb702abfd5312b1c8c719f4ecf;p=thirdparty%2Fsystemd.git loop-util: keep track of inode/devnum of backing file --- diff --git a/src/shared/loop-util.c b/src/shared/loop-util.c index 6e187efe94b..96a42b41257 100644 --- a/src/shared/loop-util.c +++ b/src/shared/loop-util.c @@ -595,6 +595,8 @@ static int loop_device_make_internal( } d->backing_file = TAKE_PTR(backing_file); + d->backing_inode = st.st_ino; + d->backing_devno = st.st_dev; log_debug("Successfully acquired %s, devno=%u:%u, nr=%i, diskseq=%" PRIu64, d->node, @@ -841,11 +843,12 @@ int loop_device_open( _cleanup_close_ int fd = -EBADF, lock_fd = -EBADF; _cleanup_free_ char *node = NULL, *backing_file = NULL; + dev_t devnum, backing_devno = 0; struct loop_info64 info; + ino_t backing_inode = 0; uint64_t diskseq = 0; LoopDevice *d; const char *s; - dev_t devnum; int r, nr = -1; assert(dev); @@ -878,6 +881,9 @@ int loop_device_open( if (!backing_file) return -ENOMEM; } + + backing_devno = info.lo_device; + backing_inode = info.lo_inode; } r = fd_get_diskseq(fd, &diskseq); @@ -913,6 +919,8 @@ int loop_device_open( .node = TAKE_PTR(node), .dev = sd_device_ref(dev), .backing_file = TAKE_PTR(backing_file), + .backing_inode = backing_inode, + .backing_devno = backing_devno, .relinquished = true, /* It's not ours, don't try to destroy it when this object is freed */ .devno = devnum, .diskseq = diskseq, diff --git a/src/shared/loop-util.h b/src/shared/loop-util.h index 5c79ed7ccee..ea461434e9c 100644 --- a/src/shared/loop-util.h +++ b/src/shared/loop-util.h @@ -14,12 +14,14 @@ struct LoopDevice { unsigned n_ref; int fd; int lock_fd; - int nr; /* The loopback device index (i.e. 4 for /dev/loop4); if this object encapsulates a non-loopback block device, set to -1 */ - dev_t devno; + int nr; /* The loopback device index (i.e. 4 for /dev/loop4); if this object encapsulates a non-loopback block device, set to -1 */ + dev_t devno; /* The loopback device's own dev_t */ char *node; sd_device *dev; char *backing_file; bool relinquished; + dev_t backing_devno; /* The backing file's dev_t */ + ino_t backing_inode; /* The backing file's ino_t */ uint64_t diskseq; /* Block device sequence number, monothonically incremented by the kernel on create/attach, or 0 if we don't know */ uint64_t uevent_seqnum_not_before; /* uevent sequm right before we attached the loopback device, or UINT64_MAX if we don't know */ usec_t timestamp_not_before; /* CLOCK_MONOTONIC timestamp taken immediately before attaching the loopback device, or USEC_INFINITY if we don't know */