loop-util: keep track of inode/devnum of backing file

This commit is contained in:
Lennart Poettering
2023-03-09 16:40:55 +01:00
parent be86e98350
commit 4d2a9e3ea6
2 changed files with 13 additions and 3 deletions
+9 -1
View File
@@ -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,
+4 -2
View File
@@ -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 */