ia64/xen-unstable

changeset 15764:f88eea67a469

[IA64] 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

Signed-off-by: Aron Griffis <aron@hp.com>
author Alex Williamson <alex.williamson@hp.com>
date Tue Aug 28 12:25:37 2007 -0600 (2007-08-28)
parents c21bd325088a
children 9341dd055619
files tools/libxc/ia64/xc_ia64_hvm_build.c
line diff
     1.1 --- a/tools/libxc/ia64/xc_ia64_hvm_build.c	Tue Aug 28 12:24:27 2007 -0600
     1.2 +++ b/tools/libxc/ia64/xc_ia64_hvm_build.c	Tue Aug 28 12:25:37 2007 -0600
     1.3 @@ -5,6 +5,7 @@
     1.4  #include "xc_elf.h"
     1.5  #include "xc_efi.h"
     1.6  #include <stdlib.h>
     1.7 +#include <unistd.h>
     1.8  #include <assert.h>
     1.9  #include <zlib.h>
    1.10  #include "xen/arch-ia64.h"
    1.11 @@ -596,7 +597,7 @@ copy_from_nvram_to_GFW(int xc_handle, ui
    1.12      unsigned int nr_pages = NVRAM_SIZE >> PAGE_SHIFT;
    1.13      struct stat file_stat;
    1.14      char buf[NVRAM_SIZE] = {0};
    1.15 -	
    1.16 +
    1.17      if ( fstat(nvram_fd, &file_stat) < 0 )
    1.18      {
    1.19          PERROR("Cannot get Nvram file info! Guest will boot without "
    1.20 @@ -751,7 +752,7 @@ int xc_ia64_save_to_nvram(int xc_handle,
    1.21          PERROR("Nvram not initialized. Nvram save failed!\n");
    1.22      else
    1.23          copy_from_GFW_to_nvram(xc_handle, dom, (int)nvram_fd);	
    1.24 -	
    1.25 +
    1.26      // although save to nvram maybe fail, we don't return any error number
    1.27      // to Xend. This is quite logical because damage of NVRAM on native would 
    1.28      // not block OS's executive path. Return error number will cause an
    1.29 @@ -759,43 +760,41 @@ int xc_ia64_save_to_nvram(int xc_handle,
    1.30      return 0;
    1.31  }
    1.32  
    1.33 -#define NVRAM_DIR       "/usr/lib/xen/boot/"
    1.34 -#define NVRAM_FILE_PATH "/usr/lib/xen/boot/nvram_"
    1.35 +#define NVRAM_DIR         "/var/lib/xen/nvram/"
    1.36 +#define NVRAM_FILE_PREFIX "nvram_"
    1.37  
    1.38  int xc_ia64_nvram_init(int xc_handle, char *dom_name, uint32_t dom)
    1.39  {
    1.40 -    int file_path_len = strlen(NVRAM_FILE_PATH);
    1.41 -    uint64_t nvram_fd = 0;
    1.42 -    char nvram_path[100] = {0};
    1.43 -    struct stat stat_buf;
    1.44 +    uint64_t nvram_fd;
    1.45 +    char nvram_path[PATH_MAX] = NVRAM_DIR;
    1.46  
    1.47 -    if ( stat(NVRAM_DIR, &stat_buf) == -1 ) {
    1.48 +    if ( access(nvram_path, R_OK|W_OK|X_OK) == -1 ) {
    1.49          if ( errno != ENOENT )
    1.50          {
    1.51 -            PERROR("Error stat'ing NVRAM dir %s.", NVRAM_DIR);
    1.52 +            PERROR("Error stat'ing NVRAM dir %s.", nvram_path);
    1.53              return -1;
    1.54          }
    1.55 -        if ( mkdir(NVRAM_DIR, 0755) == -1 )
    1.56 +        if ( mkdir(nvram_path, 0755) == -1 )
    1.57          {
    1.58 -            PERROR("Unable to create NVRAM store directory %s.", NVRAM_DIR);
    1.59 +            PERROR("Unable to create NVRAM store directory %s.", nvram_path);
    1.60              return -1;
    1.61          }
    1.62      }
    1.63  
    1.64 -    if ( !(stat_buf.st_mode & S_IRUSR) || !(stat_buf.st_mode & S_IWUSR) )
    1.65 -    {
    1.66 +    if ( access(nvram_path, R_OK|W_OK|X_OK) == -1 ) {
    1.67          errno = EACCES;
    1.68 -        PERROR("No R/W permission to NVRAM store directory %s.", NVRAM_DIR);
    1.69 +        PERROR("No RWX permission to NVRAM store directory %s.", nvram_path);
    1.70          return -1;
    1.71      }
    1.72  
    1.73 -    strncpy(nvram_path, NVRAM_FILE_PATH, file_path_len);
    1.74 -    if ( file_path_len + strlen(dom_name) + 1 > sizeof(nvram_path) )
    1.75 +    if ( strlen(nvram_path) + strlen(NVRAM_FILE_PREFIX) +
    1.76 +         strlen(dom_name) + 1 > sizeof(nvram_path) )
    1.77      {
    1.78          PERROR("Nvram file path is too long!\n");
    1.79          return -1;
    1.80      }
    1.81 -    strcpy(nvram_path + file_path_len, dom_name);
    1.82 +    strcat(nvram_path, NVRAM_FILE_PREFIX);
    1.83 +    strcat(nvram_path, dom_name);
    1.84  
    1.85      nvram_fd = nvram_init(nvram_path);
    1.86      if ( nvram_fd == (uint64_t)(-1) )