} state;
};
-static void pakfire_snapshot_free(struct pakfire_snapshot* snapshot) {
+static void pakfire_snapshot_free(struct pakfire_snapshot* self) {
// Ensure this is umounted
- pakfire_snapshot_umount(snapshot);
+ pakfire_snapshot_umount(self);
- if (snapshot->fd >= 0)
- close(snapshot->fd);
+ if (self->fd >= 0)
+ close(self->fd);
- if (snapshot->ctx)
- pakfire_ctx_unref(snapshot->ctx);
- free(snapshot);
+ if (self->ctx)
+ pakfire_ctx_unref(self->ctx);
+ free(self);
}
int pakfire_snapshot_create(
struct pakfire_snapshot** snapshot, struct pakfire_ctx* ctx, const char* path) {
- struct pakfire_snapshot* s = NULL;
+ struct pakfire_snapshot* self = NULL;
int r;
// Allocate a new snapshot
- s = calloc(1, sizeof(*s));
- if (!s)
+ self = calloc(1, sizeof(*self));
+ if (!self)
return -errno;
// Store a reference to the context
- s->ctx = pakfire_ctx_ref(ctx);
+ self->ctx = pakfire_ctx_ref(ctx);
// Initialize the reference counter
- s->nrefs = 1;
+ self->nrefs = 1;
// Store the path
- r = pakfire_string_set(s->path, path);
+ r = pakfire_string_set(self->path, path);
if (r < 0)
goto ERROR;
// Open the directory
- s->fd = open(path, O_DIRECTORY|O_CLOEXEC);
- if (s->fd < 0) {
+ self->fd = open(path, O_DIRECTORY|O_CLOEXEC);
+ if (self->fd < 0) {
r = -errno;
goto ERROR;
}
// Lock the snapshot
- r = flock(s->fd, LOCK_SH);
+ r = flock(self->fd, LOCK_SH);
if (r < 0) {
- ERROR(s->ctx, "Could not lock %s: %m\n", s->path);
+ ERROR(self->ctx, "Could not lock %s: %m\n", self->path);
r = -errno;
goto ERROR;
}
// Return the snapshot
- *snapshot = s;
+ *snapshot = self;
return 0;
ERROR:
- pakfire_snapshot_free(s);
+ pakfire_snapshot_free(self);
return r;
}
-struct pakfire_snapshot* pakfire_snapshot_ref(struct pakfire_snapshot* snapshot) {
- ++snapshot->nrefs;
+struct pakfire_snapshot* pakfire_snapshot_ref(struct pakfire_snapshot* self) {
+ ++self->nrefs;
- return snapshot;
+ return self;
}
-struct pakfire_snapshot* pakfire_snapshot_unref(struct pakfire_snapshot* snapshot) {
- if (--snapshot->nrefs > 0)
- return snapshot;
+struct pakfire_snapshot* pakfire_snapshot_unref(struct pakfire_snapshot* self) {
+ if (--self->nrefs > 0)
+ return self;
- pakfire_snapshot_free(snapshot);
+ pakfire_snapshot_free(self);
return NULL;
}
return r;
}
-static int pakfire_snapshot_mount_tmpfs(struct pakfire_snapshot* snapshot) {
+static int pakfire_snapshot_mount_tmpfs(struct pakfire_snapshot* self) {
char* path = NULL;
int r;
// Make path
- r = pakfire_string_set(snapshot->tmpfs, PAKFIRE_TMP_DIR "/pakfire-tmpfs.XXXXXX");
+ r = pakfire_string_set(self->tmpfs, PAKFIRE_TMP_DIR "/pakfire-tmpfs.XXXXXX");
if (r < 0)
return r;
// Create a temporary directory
- path = pakfire_mkdtemp(snapshot->tmpfs);
+ path = pakfire_mkdtemp(self->tmpfs);
if (!path)
return -errno;
// Perform mount
- r = mount("pakfire_tmpfs", snapshot->tmpfs, "tmpfs", 0, NULL);
+ r = mount("pakfire_tmpfs", self->tmpfs, "tmpfs", 0, NULL);
if (r < 0)
return -errno;
// Make the upper directory
- r = pakfire_path_append(snapshot->upperdir, snapshot->tmpfs, "upper");
+ r = pakfire_path_append(self->upperdir, self->tmpfs, "upper");
if (r < 0)
return r;
// Create the upper directory
- r = pakfire_mkdir(snapshot->upperdir, 0755);
+ r = pakfire_mkdir(self->upperdir, 0755);
if (r < 0)
return r;
// Make the work directory
- r = pakfire_path_append(snapshot->workdir, snapshot->tmpfs, "work");
+ r = pakfire_path_append(self->workdir, self->tmpfs, "work");
if (r < 0)
return r;
// Create the work directory
- r = pakfire_mkdir(snapshot->workdir, 0755);
+ r = pakfire_mkdir(self->workdir, 0755);
if (r < 0)
return r;
return 0;
}
-int pakfire_snapshot_mount(struct pakfire_snapshot* snapshot, const char* path) {
+int pakfire_snapshot_mount(struct pakfire_snapshot* self, const char* path) {
int mountfd = -EBADF;
int fsfd = -EBADF;
int r;
- DEBUG(snapshot->ctx, "Mounting snapshot %s to %s\n", snapshot->path, path);
+ DEBUG(self->ctx, "Mounting snapshot %s to %s\n", self->path, path);
// Mount the tmpfs
- r = pakfire_snapshot_mount_tmpfs(snapshot);
+ r = pakfire_snapshot_mount_tmpfs(self);
if (r < 0)
goto ERROR;
}
// Set the lower directory
- r = fsconfig(fsfd, FSCONFIG_SET_STRING, "lowerdir", snapshot->path, 0);
+ r = fsconfig(fsfd, FSCONFIG_SET_STRING, "lowerdir", self->path, 0);
if (r < 0)
goto ERROR;
// Set the upper directory
- r = fsconfig(fsfd, FSCONFIG_SET_STRING, "upperdir", snapshot->upperdir, 0);
+ r = fsconfig(fsfd, FSCONFIG_SET_STRING, "upperdir", self->upperdir, 0);
if (r < 0)
goto ERROR;
// Set some work directory
- r = fsconfig(fsfd, FSCONFIG_SET_STRING, "workdir", snapshot->workdir, 0);
+ r = fsconfig(fsfd, FSCONFIG_SET_STRING, "workdir", self->workdir, 0);
if (r < 0)
goto ERROR;
}
// Store the path
- r = pakfire_string_set(snapshot->overlayfs, path);
+ r = pakfire_string_set(self->overlayfs, path);
if (r < 0)
goto ERROR;
goto ERROR;
// Mark as mounted
- snapshot->state = PAKFIRE_SNAPSHOT_MOUNTED;
+ self->state = PAKFIRE_SNAPSHOT_MOUNTED;
ERROR:
if (mountfd >= 0)
return r;
}
-int pakfire_snapshot_umount(struct pakfire_snapshot* snapshot) {
+int pakfire_snapshot_umount(struct pakfire_snapshot* self) {
int r;
- switch (snapshot->state) {
+ switch (self->state) {
case PAKFIRE_SNAPSHOT_MOUNTED:
// Umount the overlayfs
- if (*snapshot->overlayfs) {
- r = umount(snapshot->overlayfs);
+ if (*self->overlayfs) {
+ r = umount(self->overlayfs);
if (r < 0)
return r;
}
// Umount the tmpfs
- if (*snapshot->tmpfs) {
- r = umount(snapshot->tmpfs);
+ if (*self->tmpfs) {
+ r = umount(self->tmpfs);
if (r < 0)
return r;
- r = pakfire_rmtree(snapshot->tmpfs, 0);
+ r = pakfire_rmtree(self->tmpfs, 0);
if (r < 0)
return r;
}
// We are now umounted
- snapshot->state = PAKFIRE_SNAPSHOT_UMOUNTED;
+ self->state = PAKFIRE_SNAPSHOT_UMOUNTED;
break;
default:
return 0;
}
-static int pakfire_snapshot_destroy(struct pakfire_snapshot* snapshot) {
+static int pakfire_snapshot_destroy(struct pakfire_snapshot* self) {
int r;
// Check if the snapshot is mounted
- switch (snapshot->state) {
+ switch (self->state) {
case PAKFIRE_SNAPSHOT_MOUNTED:
- DEBUG(snapshot->ctx, "Snapshot is mounted\n");
+ DEBUG(self->ctx, "Snapshot is mounted\n");
return -EBUSY;
default:
If this fails, another process is using this snapshot.
*/
- r = flock(snapshot->fd, LOCK_EX|LOCK_NB);
+ r = flock(self->fd, LOCK_EX|LOCK_NB);
if (r < 0) {
switch (errno) {
case EWOULDBLOCK:
- DEBUG(snapshot->ctx, "Snapshot %s is used elsewhere\n", snapshot->path);
+ DEBUG(self->ctx, "Snapshot %s is used elsewhere\n", self->path);
return -EBUSY;
default:
- DEBUG(snapshot->ctx,
- "Could not acquire an exclusive lock on %s: %m\n", snapshot->path);
+ DEBUG(self->ctx,
+ "Could not acquire an exclusive lock on %s: %m\n", self->path);
break;
}
}
- INFO(snapshot->ctx, "Destroying snapshot %s\n", snapshot->path);
+ INFO(self->ctx, "Destroying snapshot %s\n", self->path);
// Remove all files
- r = pakfire_rmtree(snapshot->path, 0);
+ r = pakfire_rmtree(self->path, 0);
if (r < 0) {
- ERROR(snapshot->ctx, "Could not destroy snapshot %s: %s\n",
- snapshot->path, strerror(-r));
+ ERROR(self->ctx, "Could not destroy snapshot %s: %s\n",
+ self->path, strerror(-r));
return r;
}
// Mark as destroyed
- snapshot->state = PAKFIRE_SNAPSHOT_DESTROYED;
+ self->state = PAKFIRE_SNAPSHOT_DESTROYED;
return 0;
}