mirror of
https://github.com/systemd/systemd.git
synced 2024-10-30 14:55:37 +03:00
loop-util: make clearer how LoopDevice objects that do not encapsulate an actual loopback device are set up
This commit is contained in:
parent
4c1d50e65c
commit
7cb349f0ca
@ -719,7 +719,7 @@ LoopDevice* loop_device_unref(LoopDevice *d) {
|
||||
/* Let's open the control device early, and lock it, so that we can release our block device and
|
||||
* delete it in a synchronized fashion, and allocators won't needlessly see the block device as free
|
||||
* while we are about to delete it. */
|
||||
if (d->nr >= 0 && !d->relinquished) {
|
||||
if (!LOOP_DEVICE_IS_FOREIGN(d) && !d->relinquished) {
|
||||
control = open("/dev/loop-control", O_RDWR|O_CLOEXEC|O_NOCTTY|O_NONBLOCK);
|
||||
if (control < 0)
|
||||
log_debug_errno(errno, "Failed to open loop control device, cannot remove loop device '%s', ignoring: %m", strna(d->node));
|
||||
@ -733,7 +733,7 @@ LoopDevice* loop_device_unref(LoopDevice *d) {
|
||||
if (fsync(d->fd) < 0)
|
||||
log_debug_errno(errno, "Failed to sync loop block device, ignoring: %m");
|
||||
|
||||
if (d->nr >= 0 && !d->relinquished) {
|
||||
if (!LOOP_DEVICE_IS_FOREIGN(d) && !d->relinquished) {
|
||||
/* We are supposed to clear the loopback device. Let's do this synchronously: lock
|
||||
* the device, manually remove all partitions and then clear it. This should ensure
|
||||
* udev doesn't concurrently access the devices, and we can be reasonably sure that
|
||||
|
@ -11,7 +11,7 @@ typedef struct LoopDevice LoopDevice;
|
||||
struct LoopDevice {
|
||||
int fd;
|
||||
int lock_fd;
|
||||
int nr;
|
||||
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;
|
||||
char *node;
|
||||
bool relinquished;
|
||||
@ -20,6 +20,9 @@ struct LoopDevice {
|
||||
usec_t timestamp_not_before; /* CLOCK_MONOTONIC timestamp taken immediately before attaching the loopback device, or USEC_INFINITY if we don't know */
|
||||
};
|
||||
|
||||
/* Returns true if LoopDevice object is not actually a loopback device but some other block device we just wrap */
|
||||
#define LOOP_DEVICE_IS_FOREIGN(d) ((d)->nr < 0)
|
||||
|
||||
int loop_device_make(int fd, int open_flags, uint64_t offset, uint64_t size, uint32_t loop_flags, int lock_op, LoopDevice **ret);
|
||||
int loop_device_make_by_path(const char *path, int open_flags, uint32_t loop_flags, int lock_op, LoopDevice **ret);
|
||||
int loop_device_open(const char *loop_path, int open_flags, int lock_op, LoopDevice **ret);
|
||||
|
Loading…
Reference in New Issue
Block a user