List Info

Thread: Move nvram from /usr to /var




Move nvram from /usr to /var
country flaguser name
United States
2007-08-27 10:53:46
# HG changeset patch
# User Aron Griffis <aronhp.com>
# Date 1188229884 14400
# Node ID 7e6d764c8054202541a26cec6a44515c428df321
# Parent  36eb4e464c8c77c65aacff0a40c50bc45e067f49
Move nvram from /usr to /var

Presently nvram is stored in
/usr/lib/xen/boot/nvram_<domain> next to the guest
firmware.  This violates the FHS because /usr might be
mounted read-only.  This
patch moves the nvram storage to
/var/lib/xen/nvram/nvram_<domain>

Also clean up:
- references to stat_buf assumed that stat() had succeeded;
use access()
  instead since it's easier and doesn't require stat_buf at
all
- nvram_path[PATH_MAX] instead of nvram_path[100]
- strncpy(..., strlen(src)) is meaningless, re-order length
tests to work
  correctly

Tested on rx3600 using virt-install on RHEL;
/var/lib/xen/nvram/nvram_hvm1 was
created and used correctly.  Searching through
xen-unstable.hg, there don't
appear to be other references to the /usr location.

Signed-off-by: Aron Griffis <aronhp.com>

-#define NVRAM_DIR       "/usr/lib/xen/boot/"
-#define NVRAM_FILE_PATH
"/usr/lib/xen/boot/nvram_"
+#define NVRAM_DIR         "/var/lib/xen/nvram/"
+#define NVRAM_FILE_PREFIX "nvram_"

 int xc_ia64_nvram_init(int xc_handle, char *dom_name,
uint32_t dom)
 {
-    int file_path_len = strlen(NVRAM_FILE_PATH);
-    uint64_t nvram_fd = 0;
-    char nvram_path[100] = ;
-    struct stat stat_buf;
-
-    if ( stat(NVRAM_DIR, &stat_buf) == -1 ) {
+    uint64_t nvram_fd;
+    char nvram_path[PATH_MAX] = NVRAM_DIR;
+
+    if ( access(nvram_path, R_OK|W_OK|X_OK) == -1 ) {
         if ( errno != ENOENT )
         {
-            PERROR("Error stat'ing NVRAM dir
%s.", NVRAM_DIR);
+            PERROR("Error stat'ing NVRAM dir
%s.", nvram_path);
             return -1;
         }
-        if ( mkdir(NVRAM_DIR, 0755) == -1 )
+        if ( mkdir(nvram_path, 0755) == -1 )
         {
-            PERROR("Unable to create NVRAM store
directory %s.", NVRAM_DIR);
+            PERROR("Unable to create NVRAM store
directory %s.", nvram_path);
             return -1;
         }
     }

-    if ( !(stat_buf.st_mode & S_IRUSR) ||
!(stat_buf.st_mode & S_IWUSR) )
-    {
+    if ( access(nvram_path, R_OK|W_OK|X_OK) == -1 ) {
         errno = EACCES;
-        PERROR("No R/W permission to NVRAM store
directory %s.", NVRAM_DIR);
-        return -1;
-    }
-
-    strncpy(nvram_path, NVRAM_FILE_PATH, file_path_len);
-    if ( file_path_len + strlen(dom_name) + 1 >
sizeof(nvram_path) )
+        PERROR("No RWX permission to NVRAM store
directory %s.", nvram_path);
+        return -1;
+    }
+
+    if ( strlen(nvram_path) + strlen(NVRAM_FILE_PREFIX) +
+         strlen(dom_name) + 1 > sizeof(nvram_path) )
     {
         PERROR("Nvram file path is too
long!n");
         return -1;
     }
-    strcpy(nvram_path + file_path_len, dom_name);
+    strcat(nvram_path, NVRAM_FILE_PREFIX);
+    strcat(nvram_path, dom_name);

     nvram_fd = nvram_init(nvram_path);
     if ( nvram_fd == (uint64_t)(-1) )

diff -r 36eb4e464c8c -r 7e6d764c8054
tools/libxc/ia64/xc_ia64_hvm_build.c
--- a/tools/libxc/ia64/xc_ia64_hvm_build.c	Mon Aug 27
08:50:22 2007 -0400
+++ b/tools/libxc/ia64/xc_ia64_hvm_build.c	Mon Aug 27
11:51:24 2007 -0400
 -5,6
+5,7 
 #include "xc_elf.h"
 #include "xc_efi.h"
 #include <stdlib.h>
+#include <unistd.h>
 #include <assert.h>
 #include <zlib.h>
 #include "xen/arch-ia64.h"
 -596,7
+597,7  copy_from_nvram_to_GFW(int xc_handle, ui
     unsigned int nr_pages = NVRAM_SIZE >>
PAGE_SHIFT;
     struct stat file_stat;
     char buf[NVRAM_SIZE] = ;
-	
+
     if ( fstat(nvram_fd, &file_stat) < 0 )
     {
         PERROR("Cannot get Nvram file info! Guest will
boot without "
 -751,7
+752,7  int xc_ia64_save_to_nvram(int xc_handle,
         PERROR("Nvram not initialized. Nvram save
failed!n");
     else
         copy_from_GFW_to_nvram(xc_handle, dom,
(int)nvram_fd);	
-	
+
     // although save to nvram maybe fail, we don't return
any error number
     // to Xend. This is quite logical because damage of
NVRAM on native would 
     // not block OS's executive path. Return error number
will cause an
 -759,43
+760,41  int xc_ia64_save_to_nvram(int xc_handle,
     return 0;
 }
 
-#define NVRAM_DIR       "/usr/lib/xen/boot/"
-#define NVRAM_FILE_PATH
"/usr/lib/xen/boot/nvram_"
+#define NVRAM_DIR         "/var/lib/xen/nvram/"
+#define NVRAM_FILE_PREFIX "nvram_"
 
 int xc_ia64_nvram_init(int xc_handle, char *dom_name,
uint32_t dom)
 {
-    int file_path_len = strlen(NVRAM_FILE_PATH);
-    uint64_t nvram_fd = 0;
-    char nvram_path[100] = ;
-    struct stat stat_buf;
-
-    if ( stat(NVRAM_DIR, &stat_buf) == -1 ) {
+    uint64_t nvram_fd;
+    char nvram_path[PATH_MAX] = NVRAM_DIR;
+
+    if ( access(nvram_path, R_OK|W_OK|X_OK) == -1 ) {
         if ( errno != ENOENT )
         {
-            PERROR("Error stat'ing NVRAM dir
%s.", NVRAM_DIR);
+            PERROR("Error stat'ing NVRAM dir
%s.", nvram_path);
             return -1;
         }
-        if ( mkdir(NVRAM_DIR, 0755) == -1 )
+        if ( mkdir(nvram_path, 0755) == -1 )
         {
-            PERROR("Unable to create NVRAM store
directory %s.", NVRAM_DIR);
+            PERROR("Unable to create NVRAM store
directory %s.", nvram_path);
             return -1;
         }
     }
 
-    if ( !(stat_buf.st_mode & S_IRUSR) ||
!(stat_buf.st_mode & S_IWUSR) )
-    {
+    if ( access(nvram_path, R_OK|W_OK|X_OK) == -1 ) {
         errno = EACCES;
-        PERROR("No R/W permission to NVRAM store
directory %s.", NVRAM_DIR);
-        return -1;
-    }
-
-    strncpy(nvram_path, NVRAM_FILE_PATH, file_path_len);
-    if ( file_path_len + strlen(dom_name) + 1 >
sizeof(nvram_path) )
+        PERROR("No RWX permission to NVRAM store
directory %s.", nvram_path);
+        return -1;
+    }
+
+    if ( strlen(nvram_path) + strlen(NVRAM_FILE_PREFIX) +
+         strlen(dom_name) + 1 > sizeof(nvram_path) )
     {
         PERROR("Nvram file path is too
long!n");
         return -1;
     }
-    strcpy(nvram_path + file_path_len, dom_name);
+    strcat(nvram_path, NVRAM_FILE_PREFIX);
+    strcat(nvram_path, dom_name);
 
     nvram_fd = nvram_init(nvram_path);
     if ( nvram_fd == (uint64_t)(-1) )

_______________________________________________
Xen-ia64-devel mailing list
Xen-ia64-devellists.xensource.com
http://list
s.xensource.com/xen-ia64-devel

Re: Move nvram from /usr to /var
country flaguser name
United States
2007-08-27 10:56:31
Aron Griffis wrote:  [Mon Aug 27 2007, 11:53:46AM EDT]
> # HG changeset patch
> # User Aron Griffis <aronhp.com>
> # Date 1188229884 14400
> # Node ID 7e6d764c8054202541a26cec6a44515c428df321
> # Parent  36eb4e464c8c77c65aacff0a40c50bc45e067f49
> Move nvram from /usr to /var

Sorry, I accidentally included part of the diff in the log
message.
I'll resend.

Aron

_______________________________________________
Xen-ia64-devel mailing list
Xen-ia64-devellists.xensource.com
http://list
s.xensource.com/xen-ia64-devel

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )