[PATCH] let stage2= honor NFS options by consolidating option parsing in loader

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

As requested by Radek Vykydal, please find attached my two updated
patches for bug 529197 (stage2= does not honor NFS options).

At the request of Chris Lumens I rewrote my earlier patch to
consolidate the parsing code for NFS options.

The first patch is against f12-branch d04d7f33, and is the one I
tested, both with and without NFS options for both ks= and stage2=
(well to be complete: I tested this against f12-branch from a few days
ago, I only compile tested this rebased version).

The second patch is against master 99dc7621, which I only compile tested
since I do not know how to compose a bootable initrd.img with anaconda
13.xx.

Happy to receive your commments, please CC me as I'm not subscribed,

--Stijn
>From 2855ddd9c04fd49ae7b4ec6d3ef5408dd6a4bdc1 Mon Sep 17 00:00:00 2001
From: Stijn Hoop <stijn@xxxxxxxxxx>
Date: Fri, 16 Oct 2009 10:04:31 +0200
Subject: [PATCH] Consolidate the parsing of nfs: locations for ks= and stage2=

Makes sure that NFS options can be used in both parameters. Previously
this was only parsed for ks= and not for stage2= using two separate
code paths. Move this to a shared function in loader/nfsinstall.c.
---
 loader/method.c     |   10 +++-----
 loader/nfsinstall.c |   52 +++++++++++++++++++++++++++++---------------------
 loader/nfsinstall.h |    1 +
 3 files changed, 35 insertions(+), 28 deletions(-)

diff --git a/loader/method.c b/loader/method.c
index 18069de..ebfe557 100644
--- a/loader/method.c
+++ b/loader/method.c
@@ -505,12 +505,10 @@ void setStage2LocFromCmdline(char * arg, struct loaderData_s * ld) {
             ld->method = METHOD_NFS;
             ld->stage2Data = calloc(sizeof(struct nfsInstallData *), 1);
 
-            ((struct nfsInstallData *)ld->stage2Data)->mountOpts = NULL;
-            ((struct nfsInstallData *)ld->stage2Data)->host = strdup(c);
-            if ((c = strtok(NULL, ":")))
-                ((struct nfsInstallData *)ld->stage2Data)->directory = strdup(c);
-            else
-                ((struct nfsInstallData *)ld->stage2Data)->directory = NULL;
+            parseNfsHostPathOpts(arg + 4,
+              &(((struct nfsInstallData *)ld->stage2Data)->host),
+              &(((struct nfsInstallData *)ld->stage2Data)->directory),
+              &(((struct nfsInstallData *)ld->stage2Data)->mountOpts));
         } else if (!strncmp(arg, "ftp:", 4) || 
                    !strncmp(arg, "http", 4)) {
             ld->method = METHOD_URL;
diff --git a/loader/nfsinstall.c b/loader/nfsinstall.c
index 6fc77ef..e405df9 100644
--- a/loader/nfsinstall.c
+++ b/loader/nfsinstall.c
@@ -108,26 +108,42 @@ static int nfsGetSetup(char ** hostptr, char ** dirptr) {
     return 0;
 }
 
-static void getHostAndPath(char *ksSource, char **host, char **file, char *ip) {
+void parseNfsHostPathOpts(char *url, char **host, char **path, char **opts) {
     char *tmp;
     char *hostsrc;
 
-    hostsrc = strdup(ksSource);
+    logMessage(DEBUGLVL, "parseNfsHostPathOpts url: |%s|", url);
+
+    hostsrc = strdup(url);
     *host = hostsrc;
-    tmp = strchr(*host, '/');
+    tmp = strchr(*host, ':');
 
     if (tmp) {
-       *file = strdup(tmp);
+       *path = strdup(tmp + 1);
        *tmp = '\0';
     }
     else {
-        *file = malloc(sizeof(char *));
-        **file = '\0';
+        *path = malloc(sizeof(char *));
+        **path = '\0';
+    }
+
+    tmp = strchr(*path, ':');
+    if (tmp && (strlen(tmp) > 1)) {
+	char * c = tmp;
+        *opts = *host;
+        *host = *path;
+	*path = strdup(c + 1);
+	*c = '\0';
+    } else {
+	*opts = NULL;
     }
 
-    logMessage(DEBUGLVL, "getHostAndPath host: |%s|", *host);
-    logMessage(DEBUGLVL, "getHostAndPath file(1): |%s|", *file);
+    logMessage(DEBUGLVL, "parseNfsHostPathOpts host: |%s|", *host);
+    logMessage(DEBUGLVL, "parseNfsHostPathOpts path: |%s|", *path);
+    logMessage(DEBUGLVL, "parseNfsHostPathOpts opts: |%s|", *opts);
+}
 
+static void addDefaultKickstartFile(char **file, char *ip) {
     /* if the filename ends with / or is null, use default kickstart
      * name of IP_ADDRESS-kickstart appended to *file
      */
@@ -138,7 +154,7 @@ static void getHostAndPath(char *ksSource, char **host, char **file, char *ip) {
             abort();
         }
 
-        logMessage(DEBUGLVL, "getHostAndPath file(2): |%s|", *file);
+        logMessage(DEBUGLVL, "addDefaultKickstartFile file: |%s|", *file);
     }
 }
 
@@ -515,17 +531,9 @@ int getFileFromNfs(char * url, char * dest, struct loaderData_s * loaderData) {
     }
 
     logMessage(INFO, "url is %s", url);
-    getHostAndPath(url, &host, &path, ip);
-
-    opts = strchr(host, ':');
-    if (opts && (strlen(opts) > 1)) {
-        char * c = opts;
-        opts = host;
-        host = c + 1;
-        *c = '\0';
-    } else {
-        opts = NULL;
-    }
+
+    parseNfsHostPathOpts(url, &host, &path, &opts);
+    addDefaultKickstartFile(&path, ip);
 
     /* nfs has to be a little bit different... split off the last part as
      * the file and then concatenate host + dir path */
@@ -537,12 +545,12 @@ int getFileFromNfs(char * url, char * dest, struct loaderData_s * loaderData) {
         chk = host + strlen(host)-1;
 
         if (*chk == '/' || *path == '/') {
-            if (asprintf(&host, "%s%s", host, path) == -1) {
+            if (asprintf(&host, "%s:%s", host, path) == -1) {
                 logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
                 abort();
             }
         } else {
-            if (asprintf(&host, "%s/%s", host, path) == -1) {
+            if (asprintf(&host, "%s:/%s", host, path) == -1) {
                 logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
                 abort();
             }
diff --git a/loader/nfsinstall.h b/loader/nfsinstall.h
index 95d76d6..99a8b06 100644
--- a/loader/nfsinstall.h
+++ b/loader/nfsinstall.h
@@ -35,5 +35,6 @@ int kickstartFromNfs(char * url, struct loaderData_s * loaderData);
 char * mountNfsImage(struct installMethod * method,
                      char * location, struct loaderData_s * loaderData);
 int getFileFromNfs(char * url, char * dest, struct loaderData_s * loaderData);
+void parseNfsHostPathOpts(char * url, char ** host, char ** path, char ** opts);
 
 #endif
-- 
1.6.5.rc2

>From 2855ddd9c04fd49ae7b4ec6d3ef5408dd6a4bdc1 Mon Sep 17 00:00:00 2001
From: Stijn Hoop <stijn@xxxxxxxxxx>
Date: Fri, 16 Oct 2009 10:04:31 +0200
Subject: [PATCH] Consolidate the parsing of nfs: locations for ks= and stage2=

Makes sure that NFS options can be used in both parameters. Previously
this was only parsed for ks= and not for stage2= using two separate
code paths. Move this to a shared function in loader/nfsinstall.c.
---
 loader/method.c     |   10 +++-----
 loader/nfsinstall.c |   52 +++++++++++++++++++++++++++++---------------------
 loader/nfsinstall.h |    1 +
 3 files changed, 35 insertions(+), 28 deletions(-)

diff --git a/loader/method.c b/loader/method.c
index 18069de..ebfe557 100644
--- a/loader/method.c
+++ b/loader/method.c
@@ -505,12 +505,10 @@ void setStage2LocFromCmdline(char * arg, struct loaderData_s * ld) {
             ld->method = METHOD_NFS;
             ld->stage2Data = calloc(sizeof(struct nfsInstallData *), 1);
 
-            ((struct nfsInstallData *)ld->stage2Data)->mountOpts = NULL;
-            ((struct nfsInstallData *)ld->stage2Data)->host = strdup(c);
-            if ((c = strtok(NULL, ":")))
-                ((struct nfsInstallData *)ld->stage2Data)->directory = strdup(c);
-            else
-                ((struct nfsInstallData *)ld->stage2Data)->directory = NULL;
+            parseNfsHostPathOpts(arg + 4,
+              &(((struct nfsInstallData *)ld->stage2Data)->host),
+              &(((struct nfsInstallData *)ld->stage2Data)->directory),
+              &(((struct nfsInstallData *)ld->stage2Data)->mountOpts));
         } else if (!strncmp(arg, "ftp:", 4) || 
                    !strncmp(arg, "http", 4)) {
             ld->method = METHOD_URL;
diff --git a/loader/nfsinstall.c b/loader/nfsinstall.c
index 6fc77ef..e405df9 100644
--- a/loader/nfsinstall.c
+++ b/loader/nfsinstall.c
@@ -108,26 +108,42 @@ static int nfsGetSetup(char ** hostptr, char ** dirptr) {
     return 0;
 }
 
-static void getHostAndPath(char *ksSource, char **host, char **file, char *ip) {
+void parseNfsHostPathOpts(char *url, char **host, char **path, char **opts) {
     char *tmp;
     char *hostsrc;
 
-    hostsrc = strdup(ksSource);
+    logMessage(DEBUGLVL, "parseNfsHostPathOpts url: |%s|", url);
+
+    hostsrc = strdup(url);
     *host = hostsrc;
-    tmp = strchr(*host, '/');
+    tmp = strchr(*host, ':');
 
     if (tmp) {
-       *file = strdup(tmp);
+       *path = strdup(tmp + 1);
        *tmp = '\0';
     }
     else {
-        *file = malloc(sizeof(char *));
-        **file = '\0';
+        *path = malloc(sizeof(char *));
+        **path = '\0';
+    }
+
+    tmp = strchr(*path, ':');
+    if (tmp && (strlen(tmp) > 1)) {
+	char * c = tmp;
+        *opts = *host;
+        *host = *path;
+	*path = strdup(c + 1);
+	*c = '\0';
+    } else {
+	*opts = NULL;
     }
 
-    logMessage(DEBUGLVL, "getHostAndPath host: |%s|", *host);
-    logMessage(DEBUGLVL, "getHostAndPath file(1): |%s|", *file);
+    logMessage(DEBUGLVL, "parseNfsHostPathOpts host: |%s|", *host);
+    logMessage(DEBUGLVL, "parseNfsHostPathOpts path: |%s|", *path);
+    logMessage(DEBUGLVL, "parseNfsHostPathOpts opts: |%s|", *opts);
+}
 
+static void addDefaultKickstartFile(char **file, char *ip) {
     /* if the filename ends with / or is null, use default kickstart
      * name of IP_ADDRESS-kickstart appended to *file
      */
@@ -138,7 +154,7 @@ static void getHostAndPath(char *ksSource, char **host, char **file, char *ip) {
             abort();
         }
 
-        logMessage(DEBUGLVL, "getHostAndPath file(2): |%s|", *file);
+        logMessage(DEBUGLVL, "addDefaultKickstartFile file: |%s|", *file);
     }
 }
 
@@ -515,17 +531,9 @@ int getFileFromNfs(char * url, char * dest, struct loaderData_s * loaderData) {
     }
 
     logMessage(INFO, "url is %s", url);
-    getHostAndPath(url, &host, &path, ip);
-
-    opts = strchr(host, ':');
-    if (opts && (strlen(opts) > 1)) {
-        char * c = opts;
-        opts = host;
-        host = c + 1;
-        *c = '\0';
-    } else {
-        opts = NULL;
-    }
+
+    parseNfsHostPathOpts(url, &host, &path, &opts);
+    addDefaultKickstartFile(&path, ip);
 
     /* nfs has to be a little bit different... split off the last part as
      * the file and then concatenate host + dir path */
@@ -537,12 +545,12 @@ int getFileFromNfs(char * url, char * dest, struct loaderData_s * loaderData) {
         chk = host + strlen(host)-1;
 
         if (*chk == '/' || *path == '/') {
-            if (asprintf(&host, "%s%s", host, path) == -1) {
+            if (asprintf(&host, "%s:%s", host, path) == -1) {
                 logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
                 abort();
             }
         } else {
-            if (asprintf(&host, "%s/%s", host, path) == -1) {
+            if (asprintf(&host, "%s:/%s", host, path) == -1) {
                 logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
                 abort();
             }
diff --git a/loader/nfsinstall.h b/loader/nfsinstall.h
index 95d76d6..99a8b06 100644
--- a/loader/nfsinstall.h
+++ b/loader/nfsinstall.h
@@ -35,5 +35,6 @@ int kickstartFromNfs(char * url, struct loaderData_s * loaderData);
 char * mountNfsImage(struct installMethod * method,
                      char * location, struct loaderData_s * loaderData);
 int getFileFromNfs(char * url, char * dest, struct loaderData_s * loaderData);
+void parseNfsHostPathOpts(char * url, char ** host, char ** path, char ** opts);
 
 #endif
-- 
1.6.5.rc2

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

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux