Since mount can handle mounting files on loopback for us now, there's no
reason to continue doing so manually in loader.
---
loader/driverdisk.c | 10 +++---
loader/hdinstall.c | 2 +-
loader/method.c | 89 +++---------------------------------------------
loader/method.h | 5 ---
loader/urlinstall.c | 19 +++++-----
pyanaconda/backend.py | 14 +++++++-
6 files changed, 34 insertions(+), 105 deletions(-)
diff --git a/loader/driverdisk.c b/loader/driverdisk.c
index 951b29b..ada8e81 100644
--- a/loader/driverdisk.c
+++ b/loader/driverdisk.c
@@ -497,13 +497,13 @@ int loadDriverFromMedia(int class, struct loaderData_s *loaderData,
break;
}
if (dir == -1) {
- umountLoopback("/tmp/drivers", "/dev/loop6");
+ umount("/tmp/drivers");
unlink("/tmp/drivers");
ddfile = NULL;
stage = DEV_CHOOSEFILE;
break;
}
- if (mountLoopback(ddfile, "/tmp/drivers", "/dev/loop6")) {
+ if (doPwMount(ddfile, "/tmp/drivers", "auto", "ro", NULL)) {
newtWinMessage(_("Error"), _("OK"),
_("Failed to load driver disk from file."));
stage = DEV_CHOOSEFILE;
@@ -575,7 +575,7 @@ int loadDriverFromMedia(int class, struct loaderData_s *loaderData,
stage = DEV_PROBE;
if (ddfile != NULL) {
- umountLoopback("/tmp/drivers", "/dev/loop6");
+ umount("/tmp/drivers");
unlink("/tmp/drivers");
umount("/tmp/dpart");
}
@@ -717,9 +717,9 @@ void getDDFromSource(struct loaderData_s * loaderData, char * src, GTree *module
return;
}
- if (!mountLoopback(path, "/tmp/drivers", "/dev/loop6")) {
+ if (!doPwMount(path, "/tmp/drivers", "auto", "ro", NULL)) {
loadFromLocation(loaderData, "/tmp/drivers", moduleState);
- umountLoopback("/tmp/drivers", "/dev/loop6");
+ umount("/tmp/drivers");
unlink("/tmp/drivers");
if (unlinkf) unlink(path);
}
diff --git a/loader/hdinstall.c b/loader/hdinstall.c
index 4514404..e8c9873 100644
--- a/loader/hdinstall.c
+++ b/loader/hdinstall.c
@@ -77,7 +77,7 @@ static char * setupIsoImages(char * device, char * dirName, char * location) {
free(path);
if (rc) {
- umountLoopback("/mnt/runtime", "/dev/loop0");
+ umount("/mnt/runtime");
umount("/mnt/isodir");
goto err;
}
diff --git a/loader/method.c b/loader/method.c
index a00e02c..e2f4b3b 100644
--- a/loader/method.c
+++ b/loader/method.c
@@ -68,48 +68,6 @@ static void stripTrailingSlash(char *path) {
path[len-1] = '\0';
}
-int umountLoopback(char * mntpoint, char * device) {
- int loopfd;
-
- umount(mntpoint);
-
- logMessage(INFO, "umounting loopback %s %s", mntpoint, device);
-
- loopfd = open(device, O_RDONLY);
-
- if (ioctl(loopfd, LOOP_CLR_FD, 0) == -1)
- logMessage(ERROR, "LOOP_CLR_FD failed for %s %s: %m", mntpoint, device);
-
- close(loopfd);
-
- return 0;
-}
-
-int mountLoopback(char *fsystem, char *mntpoint, char *device) {
- char *opts, *err = NULL;
-
- if (device == NULL) {
- logMessage(ERROR, "no loopback device given");
- return LOADER_ERROR;
- }
-
- if (access(fsystem, F_OK) != 0) {
- logMessage(ERROR, "file %s is not accessible", fsystem);
- return LOADER_ERROR;
- }
-
- checked_asprintf(&opts, "ro,loop=%s", device);
-
- logMessage(INFO, "attempting to attach file %s to loopback device %s and mount on %s", fsystem, mntpoint, device);
-
- if (doPwMount(fsystem, mntpoint, "auto", opts, &err)) {
- logMessage(ERROR, "failed loopback mount: %s", err);
- return LOADER_ERROR;
- }
-
- return 0;
-}
-
/* returns the *absolute* path (malloced) to the #1 iso image */
/* get timestamp and description of ISO image from stamp file */
/* returns 0 on success, -1 otherwise */
@@ -121,20 +79,17 @@ int readStampFileFromIso(char *file, char **timestamp, char **releasedescr) {
char *stampfile;
char *descr, *tstamp;
char tmpstr[1024];
- int filetype;
int rc;
lstat(file, &sb);
if (S_ISBLK(sb.st_mode)) {
- filetype = 1;
if (doPwMount(file, "/tmp/testmnt", "iso9660", "ro", NULL)) {
logMessage(ERROR, "Failed to mount device %s to get description",
file);
return -1;
}
} else if (S_ISREG(sb.st_mode)) {
- filetype = 2;
- if (mountLoopback(file, "/tmp/testmnt", "/dev/loop6")) {
+ if (doPwMount(file, "/tmp/testmnt", "auto", "ro", NULL)) {
logMessage(ERROR, "Failed to mount iso %s to get description",
file);
return -1;
@@ -147,8 +102,6 @@ int readStampFileFromIso(char *file, char **timestamp, char **releasedescr) {
if (!(dir = opendir("/tmp/testmnt"))) {
umount("/tmp/testmnt");
- if (filetype == 2)
- umountLoopback("/tmp/testmnt", "/dev/loop6");
return -1;
}
@@ -223,8 +176,6 @@ int readStampFileFromIso(char *file, char **timestamp, char **releasedescr) {
free(stampfile);
umount("/tmp/testmnt");
- if (filetype == 2)
- umountLoopback("/tmp/testmnt", "/dev/loop6");
if (descr != NULL && tstamp != NULL) {
descr[strlen(descr)-1] = '\0';
@@ -395,10 +346,10 @@ int unpackCpioBall(char * ballPath, char * rootDir) {
void copyUpdatesImg(char * path) {
if (!access(path, R_OK)) {
- if (!mountLoopback(path, "/tmp/update-disk", "/dev/loop7")) {
+ if (!doPwMount(path, "/tmp/update-disk", "auto", "ro", NULL)) {
copyDirectory("/tmp/update-disk", "/tmp/updates", copyWarnFn,
copyErrorFn);
- umountLoopback("/tmp/update-disk", "/dev/loop7");
+ umount("/tmp/update-disk");
unlink("/tmp/update-disk");
} else {
unpackCpioBall(path, "/tmp/updates");
@@ -408,10 +359,10 @@ void copyUpdatesImg(char * path) {
void copyProductImg(char * path) {
if (!access(path, R_OK)) {
- if (!mountLoopback(path, "/tmp/product-disk", "/dev/loop7")) {
+ if (!doPwMount(path, "/tmp/product-disk", "auto", "ro", NULL)) {
copyDirectory("/tmp/product-disk", "/tmp/product", copyWarnFn,
copyErrorFn);
- umountLoopback("/tmp/product-disk", "/dev/loop7");
+ umount("/tmp/product-disk");
unlink("/tmp/product-disk");
}
}
@@ -445,35 +396,7 @@ int mountStage2(char *stage2path) {
return 1;
}
- if (mountLoopback(stage2path, "/mnt/runtime", "/dev/loop0")) {
- return 1;
- }
-
- return 0;
-}
-
-
-/* copies a second stage from fd to dest and mounts on mntpoint */
-int copyFileAndLoopbackMount(int fd, char * dest, char * device, char * mntpoint,
- progressCB pbcb, struct progressCBdata *data,
- long long total) {
- int rc;
- struct stat sb;
-
- rc = copyFileFd(fd, dest, pbcb, data, total);
- stat(dest, &sb);
- logMessage(DEBUGLVL, "copied %" PRId64 " bytes to %s (%s)", sb.st_size, dest,
- ((rc) ? " incomplete" : "complete"));
-
- if (rc) {
- /* just to make sure */
- unlink(dest);
- return 1;
- }
-
- if (mountLoopback(dest, mntpoint, device)) {
- /* JKFIXME: this used to be fatal, but that seems unfriendly */
- logMessage(ERROR, "Error mounting %s on %s: %m", device, mntpoint);
+ if (doPwMount(stage2path, "/mnt/runtime", "auto", "ro", NULL)) {
return 1;
}
diff --git a/loader/method.h b/loader/method.h
index cabd1c2..967ed5d 100644
--- a/loader/method.h
+++ b/loader/method.h
@@ -39,16 +39,11 @@ struct installMethod {
char * location, struct loaderData_s * loaderData);
};
-int umountLoopback(char * mntpoint, char * device);
-int mountLoopback(char * fsystem, char * mntpoint, char * device);
-
int readStampFileFromIso(char *file, char **descr, char **timestamp);
void queryIsoMediaCheck(char * isoDir);
int mountStage2(char *stage2path);
int mountStage2Direct(char *stage2path);
-int copyFileAndLoopbackMount(int fd, char *dest, char *device, char *mntpoint,
- progressCB pbcb, struct progressCBdata *data, long long total);
int getFileFromBlockDevice(char *device, char *path, char * dest);
int unpackCpioBall(char * ballPath, char * rootDir);
diff --git a/loader/urlinstall.c b/loader/urlinstall.c
index 3610538..fda3ecb 100644
--- a/loader/urlinstall.c
+++ b/loader/urlinstall.c
@@ -32,6 +32,7 @@
#include <glib.h>
#include "../pyanaconda/isys/iface.h"
+#include "../pyanaconda/isys/imount.h"
#include "../pyanaconda/isys/log.h"
#include "copy.h"
@@ -124,7 +125,7 @@ static char **headers() {
}
static int loadSingleUrlImage(struct loaderData_s *loaderData, struct iurlinfo *ui,
- char *dest, char *mntpoint, char *device, int silentErrors) {
+ char *dest, char *mntpoint, int silentErrors) {
char **ehdrs = NULL;
int status;
@@ -142,8 +143,8 @@ static int loadSingleUrlImage(struct loaderData_s *loaderData, struct iurlinfo *
}
if (dest != NULL) {
- if (mountLoopback(dest, mntpoint, device)) {
- logMessage(ERROR, "Error mounting %s on %s: %m", device, mntpoint);
+ if (doPwMount(dest, mntpoint, "auto", "ro", NULL)) {
+ logMessage(ERROR, "Error mounting %s: %m", dest);
return 1;
}
}
@@ -180,11 +181,10 @@ static int loadUrlImages(struct loaderData_s *loaderData, struct iurlinfo *ui) {
* ramdisk usage */
checked_asprintf(&ui->url, "%s/%s", path, "updates.img");
- if (!loadSingleUrlImage(loaderData, ui, "/tmp/updates-disk.img", "/tmp/update-disk",
- "/dev/loop7", 1)) {
+ if (!loadSingleUrlImage(loaderData, ui, "/tmp/updates-disk.img", "/tmp/update-disk", 1)) {
copyDirectory("/tmp/update-disk", "/tmp/updates", copyWarnFn,
copyErrorFn);
- umountLoopback("/tmp/update-disk", "/dev/loop7");
+ umount("/tmp/update-disk");
unlink("/tmp/updates-disk.img");
unlink("/tmp/update-disk");
} else if (!access("/tmp/updates-disk.img", R_OK)) {
@@ -198,11 +198,10 @@ static int loadUrlImages(struct loaderData_s *loaderData, struct iurlinfo *ui) {
* ramdisk usage */
checked_asprintf(&ui->url, "%s/%s", path, "product.img");
- if (!loadSingleUrlImage(loaderData, ui, "/tmp/product-disk.img", "/tmp/product-disk",
- "/dev/loop7", 1)) {
+ if (!loadSingleUrlImage(loaderData, ui, "/tmp/product-disk.img", "/tmp/product-disk", 1)) {
copyDirectory("/tmp/product-disk", "/tmp/product", copyWarnFn,
copyErrorFn);
- umountLoopback("/tmp/product-disk", "/dev/loop7");
+ umount("/tmp/product-disk");
unlink("/tmp/product-disk.img");
unlink("/tmp/product-disk");
}
@@ -212,7 +211,7 @@ static int loadUrlImages(struct loaderData_s *loaderData, struct iurlinfo *ui) {
checked_asprintf(&dest, "/tmp/install.img");
- rc = loadSingleUrlImage(loaderData, ui, dest, "/mnt/runtime", "/dev/loop0", 0);
+ rc = loadSingleUrlImage(loaderData, ui, dest, "/mnt/runtime", 0);
free(dest);
free(oldUrl);
diff --git a/pyanaconda/backend.py b/pyanaconda/backend.py
index 9f253ed..0341e9f 100644
--- a/pyanaconda/backend.py
+++ b/pyanaconda/backend.py
@@ -174,7 +174,19 @@ class AnacondaBackend:
return 1
- isys.lochangefd("/dev/loop0", self._loopbackFile)
+ # Figure out which loopback device is in use for lochangefd.
+ dev = "/dev/loop0"
+ f = open("/proc/mounts", "r")
+ lines = f.readlines()
+ f.close()
+
+ for line in lines:
+ parts = line.split()
+ if parts[1] == "/mnt/runtime":
+ dev = parts[0]
+ break
+
+ isys.lochangefd(dev, self._loopbackFile)
if os.path.ismount("/mnt/stage2"):
isys.umount("/mnt/stage2")
--
1.7.1.1