FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Gentoo > Gentoo User

 
 
LinkBack Thread Tools
 
Old 10-13-2010, 03:11 PM
Chris Lumens
 
Default Rework how image loading works for NFS installs.

Break mountNfsImage apart into the two most useful things it does: (1) Display
a UI for getting NFS parameters, and (2) Fetch product.img and updates.img. It
is no longer required to get the install.img.
---
loader/loader.c | 2 +-
loader/nfsinstall.c | 173 +++++++++++++++++++++++++++++++-------------------
loader/nfsinstall.h | 4 +-
3 files changed, 110 insertions(+), 69 deletions(-)

diff --git a/loader/loader.c b/loader/loader.c
index 221be0c..942b5b5 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -131,7 +131,7 @@ static const char *LANG_DEFAULT = "en_US.UTF-8";
static struct installMethod installMethods[] = {
{ N_("Local CD/DVD"), 0, DEVICE_CDROM, NULL, NULL },
{ N_("Hard drive"), 0, DEVICE_DISK, NULL, NULL },
- { N_("NFS directory"), 1, DEVICE_NETWORK, NULL, NULL },
+ { N_("NFS directory"), 1, DEVICE_NETWORK, promptForNfs, loadNfsImages },
{ "URL", 1, DEVICE_NETWORK, promptForUrl, loadUrlImages},
};
static int numMethods = sizeof(installMethods) / sizeof(struct installMethod);
diff --git a/loader/nfsinstall.c b/loader/nfsinstall.c
index 4b600d6..dad5663 100644
--- a/loader/nfsinstall.c
+++ b/loader/nfsinstall.c
@@ -129,17 +129,29 @@ static int nfsGetSetup(char ** hostptr, char ** dirptr, char ** optsptr) {
if (*hostptr) free(*hostptr);
if (*dirptr) free(*dirptr);
if (*optsptr) free(*optsptr);
+
*hostptr = newServer;
*dirptr = newDir;
- *optsptr = newMountOpts;

- return 0;
+ /* The rest of loader expects opts to be NULL if there are none, but newt
+ * gives us "" instead.
+ */
+ if (newMountOpts && strcmp(newMountOpts, ""))
+ *optsptr = newMountOpts;
+ else
+ *optsptr = NULL;
+
+ return LOADER_OK;
}

void parseNfsHostPathOpts(char *url, char **host, char **path, char **opts) {
char *tmp;
char *hostsrc;

+ /* Skip over the leading nfs: if present. */
+ if (!strncmp(url, "nfs:", 4))
+ url += 4;
+
logMessage(DEBUGLVL, "parseNfsHostPathOpts url: |%s|", url);

hostsrc = strdup(url);
@@ -156,10 +168,10 @@ void parseNfsHostPathOpts(char *url, char **host, char **path, char **opts) {
}

tmp = strchr(*path, ':');
- if (tmp && (strlen(tmp) > 1)) {
+ if (tmp && strlen(tmp) > 1) {
char * c = tmp;
- *opts = *host;
- *host = *path;
+
+ *opts = *path;
*path = strdup(c + 1);
*c = '';
} else {
@@ -182,6 +194,88 @@ static void addDefaultKickstartFile(char **file, char *ip) {
}
}

+int promptForNfs(struct loaderData_s *loaderData) {
+ char *url = NULL;
+ char *host = NULL;
+ char *directory = NULL;
+ char *mountOpts = NULL;
+
+ do {
+ if (nfsGetSetup(&host, &directory, &mountOpts) == LOADER_BACK) {
+ loaderData->instRepo = NULL;
+ return LOADER_BACK;
+ }
+
+ if (mountOpts) {
+ checked_asprintf(&loaderData->instRepo, "nfs:%s:%s:%s", host, mountOpts,
+ directory);
+ } else {
+ checked_asprintf(&loaderData->instRepo, "nfs:%s:%s", host, directory);
+ }
+
+ checked_asprintf(&url, "%s/.treeinfo", loaderData->instRepo);
+
+ if (getFileFromNfs(url, "/tmp/.treeinfo", loaderData)) {
+ newtWinMessage(_("Error"), _("OK"),
+ _("The URL provided does not contain installation media."));
+ free(url);
+ continue;
+ }
+
+ free(url);
+ break;
+ } while (1);
+
+ loaderData->method = METHOD_NFS;
+ return LOADER_OK;
+}
+
+int loadNfsImages(struct loaderData_s *loaderData) {
+ char *host, *path, *opts;
+ char *url;
+
+ if (!loaderData->instRepo)
+ return 0;
+
+ parseNfsHostPathOpts(loaderData->instRepo, &host, &path, &opts);
+
+ checked_asprintf(&url, "%s:%s/RHupdates", host, path);
+ logMessage(INFO, "Looking for updates in %s", url);
+
+ if (!doPwMount(url, "/tmp/update-disk", "nfs", opts, NULL)) {
+ logMessage(INFO, "Using RHupdates/ for NFS install");
+ copyDirectory("/tmp/update-disk", "/tmp/updates", NULL, NULL);
+ umount("/tmp/update-disk");
+ unlink("/tmp/update-disk");
+ } else {
+ logMessage(INFO, "No RHupdates/ directory found, skipping");
+ }
+
+ free(url);
+ checked_asprintf(&url, "%s:%s", host, path);
+
+ if (!doPwMount(url, "/tmp/disk-image", "nfs", opts, NULL)) {
+ free(url);
+
+ logMessage(INFO, "Looking for updates in %s/updates.img", loaderData->instRepo);
+ copyUpdatesImg("/tmp/disk-image/updates.img");
+
+ logMessage(INFO, "Looking for product in %s/product.img", loaderData->instRepo);
+ copyProductImg("/tmp/disk-image/product.img");
+
+ umount("/tmp/disk-image");
+ unlink("/tmp/disk-image");
+ } else {
+ logMessage(INFO, "Couldn't mount %s for updates and product", loaderData->instRepo);
+ free(url);
+ }
+
+ free(host);
+ free(path);
+ free(opts);
+ return 1;
+}
+
char * mountNfsImage(struct installMethod * method,
char * location, struct loaderData_s * loaderData) {
char * host = NULL;
@@ -190,8 +284,7 @@ char * mountNfsImage(struct installMethod * method,
char * fullPath = NULL;
char * url = NULL;

- enum { NFS_STAGE_NFS, NFS_STAGE_MOUNT, NFS_STAGE_DONE,
- NFS_STAGE_UPDATES } stage = NFS_STAGE_NFS;
+ enum { NFS_STAGE_NFS, NFS_STAGE_MOUNT, NFS_STAGE_DONE } stage = NFS_STAGE_NFS;

int rc;

@@ -290,7 +383,7 @@ char * mountNfsImage(struct installMethod * method,
}

if (rc == 0) {
- stage = NFS_STAGE_UPDATES;
+ stage = NFS_STAGE_DONE;
checked_asprintf(&url, "nfs:%s:%s", host,
directory);
free(buf);
@@ -335,46 +428,6 @@ char * mountNfsImage(struct installMethod * method,
break;
}

- case NFS_STAGE_UPDATES: {
- char *buf;
-
- checked_asprintf(&buf, "%.*s/RHupdates",
- (int) (strrchr(fullPath, '/')-fullPath),
- fullPath);
- logMessage(INFO, "Looking for updates in %s", buf);
-
- if (!doPwMount(buf, "/tmp/update-disk", "nfs", mountOpts, NULL)) {
- logMessage(INFO, "Using RHupdates/ for NFS install");
- copyDirectory("/tmp/update-disk", "/tmp/updates", NULL, NULL);
- umount("/tmp/update-disk");
- unlink("/tmp/update-disk");
- } else {
- logMessage(INFO, "No RHupdates/ directory found, skipping");
- }
-
- free(buf);
-
- if (!doPwMount(fullPath, "/tmp/disk-image", "nfs", mountOpts, NULL)) {
- logMessage(INFO, "Looking for updates in %s/updates.img", fullPath);
- checked_asprintf(&buf, "/tmp/disk-image/updates.img");
- copyUpdatesImg(buf);
- free(buf);
-
- logMessage(INFO, "Looking for product in %s/product.img", fullPath);
- checked_asprintf(&buf, "/tmp/disk-image/product.img");
- copyProductImg(buf);
- free(buf);
-
- umount("/tmp/disk-image");
- unlink("/tmp/disk-image");
- } else {
- logMessage(INFO, "Couldn't mount %s for updates and product", fullPath);
- }
-
- stage = NFS_STAGE_DONE;
- break;
- }
-
case NFS_STAGE_DONE:
break;
}
@@ -426,29 +479,17 @@ void setKickstartNfs(struct loaderData_s * loaderData, int argc,
return;
}

- loaderData->method = METHOD_NFS;
- loaderData->stage2Data = NULL;
+ logMessage(INFO, "results of nfs, host is %s, dir is %s, opts are '%s'",
+ host, dir, mountOpts);

- substr = strstr(dir, ".img");
- if (!substr || (substr && *(substr+4) != '')) {
- checked_asprintf(&(loaderData->instRepo), "nfs:%s:%s", host, dir);
-
- logMessage(INFO, "results of nfs, host is %s, dir is %s, opts are '%s'",
- host, dir, mountOpts);
+ loaderData->method = METHOD_NFS;
+ if (mountOpts) {
+ checked_asprintf(&loaderData->instRepo, "nfs:%s:%s:%s", host, mountOpts, dir);
} else {
- loaderData->stage2Data = calloc(sizeof(struct nfsInstallData), 1);
- ((struct nfsInstallData *)loaderData->stage2Data)->host = host;
- ((struct nfsInstallData *)loaderData->stage2Data)->directory = dir;
- ((struct nfsInstallData *)loaderData->stage2Data)->mountOpts = mountOpts;
-
- logMessage(INFO, "results of nfs, host is %s, dir is %s, opts are '%s'",
- ((struct nfsInstallData *) loaderData->stage2Data)->host,
- ((struct nfsInstallData *) loaderData->stage2Data)->directory,
- ((struct nfsInstallData *) loaderData->stage2Data)->mountOpts);
+ checked_asprintf(&loaderData->instRepo, "nfs:%s:%s", host, dir);
}
}

-
int getFileFromNfs(char * url, char * dest, struct loaderData_s * loaderData) {
char * host = NULL, *path = NULL, * file = NULL, * opts = NULL;
char * chk = NULL, *ip = NULL;
diff --git a/loader/nfsinstall.h b/loader/nfsinstall.h
index 99a8b06..ee3ca80 100644
--- a/loader/nfsinstall.h
+++ b/loader/nfsinstall.h
@@ -32,8 +32,8 @@ struct nfsInstallData {
void setKickstartNfs(struct loaderData_s * loaderData, int argc,
char ** argv);
int kickstartFromNfs(char * url, struct loaderData_s * loaderData);
-char * mountNfsImage(struct installMethod * method,
- char * location, struct loaderData_s * loaderData);
+int promptForNfs(struct loaderData_s *loaderData);
+int loadNfsImages(struct loaderData_s *loaderData);
int getFileFromNfs(char * url, char * dest, struct loaderData_s * loaderData);
void parseNfsHostPathOpts(char * url, char ** host, char ** path, char ** opts);

--
1.7.1.1

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 

Thread Tools




All times are GMT. The time now is 03:50 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org