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

[Libvir] [PATCH 1/6] Inactive domain support: new virConf APIs



The attached patch adds two new APIs to the virConf object needed for
creating new inactive domains:

  virConfNew
  virConfSetValue

Docs for these methods are inline with the patch. The semantics of the
virConfSetValue method are changed based on previous feedback - the
'value' object passed in is now always owned by the vifConf object upon
return - even upon failure. This actually simplified the calling code
quite alot too.

Dan.
-- 
|=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 978 392 2496 -=|
|=-           Perl modules: http://search.cpan.org/~danberr/              -=|
|=-               Projects: http://freshmeat.net/~danielpb/               -=|
|=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505  -=| 
Index: src/conf.c
===================================================================
RCS file: /data/cvs/libvirt/src/conf.c,v
retrieving revision 1.4
diff -c -r1.4 conf.c
*** src/conf.c	21 Sep 2006 15:24:37 -0000	1.4
--- src/conf.c	15 Nov 2006 02:33:59 -0000
***************
*** 144,159 ****
      free(val);
  }
  
! /**
!  * virConfCreate:
!  * @filename: the name to report errors
!  *
!  * Create a configuration internal structure
!  *
!  * Returns a pointer or NULL in case of error.
!  */
! static virConfPtr
! virConfCreate(const char *filename)
  {
      virConfPtr ret;
  
--- 144,150 ----
      free(val);
  }
  
! virConfPtr virConfNew(void)
  {
      virConfPtr ret;
  
***************
*** 164,175 ****
      }
      memset(ret, 0, sizeof(virConf));
  
!     ret->filename = filename;
  
      return(ret);
  }
  
  /**
   * virConfAddEntry:
   * @conf: the conf structure
   * @name: name of the entry or NULL for comment
--- 155,183 ----
      }
      memset(ret, 0, sizeof(virConf));
  
!     ret->filename = NULL;
  
      return(ret);
  }
  
  /**
+  * virConfCreate:
+  * @filename: the name to report errors
+  *
+  * Create a configuration internal structure
+  *
+  * Returns a pointer or NULL in case of error.
+  */
+ static virConfPtr
+ virConfCreate(const char *filename)
+ {
+     virConfPtr ret = virConfNew();
+     if (ret)
+         ret->filename = filename;
+     return(ret);
+ }
+ 
+ /**
   * virConfAddEntry:
   * @conf: the conf structure
   * @name: name of the entry or NULL for comment
***************
*** 785,790 ****
--- 793,852 ----
  }
  
  /**
+  * virConfGetValue:
+  * @conf: a configuration file handle
+  * @entry: the name of the entry
+  * @value: the new configuration value
+  *
+  * Set (or replace) the value associated to this entry in the configuration
+  * file. The passed in 'value' will be owned by the conf object upon return
+  * of this method, even in case of error. It should not be referenced again
+  * by the caller.
+  *
+  * Returns 0 on success, or -1 on failure.
+  */
+ int             virConfSetValue         (virConfPtr conf,
+                                          const char *setting,
+                                          virConfValuePtr value) {
+     virConfEntryPtr cur, prev = NULL;
+ 
+     cur = conf->entries;
+     while (cur != NULL) {
+         if ((cur->name != NULL) && (!strcmp(cur->name, setting))) {
+             break;
+         }
+         prev = cur;
+         cur = cur->next;
+     }
+     if (!cur) {
+         if (!(cur = malloc(sizeof(virConfEntry)))) {
+             virConfFreeValue(value);
+             return (-1);
+         }
+         cur->next = NULL;
+         cur->comment = NULL;
+         if (!(cur->name = strdup(setting))) {
+             virConfFreeValue(value);
+             free(cur);
+             return (-1);
+         }
+         cur->value = value;
+         if (prev) {
+             prev->next = cur;
+         } else {
+             conf->entries = cur;
+         }
+     } else {
+         if (cur->value) {
+             virConfFreeValue(cur->value);
+         }
+         cur->value = value;
+     }
+     return (0);
+ }
+ 
+ 
+ /**
   * virConfWriteFile:
   * @filename: the path to the configuration file.
   * @conf: the conf
***************
*** 878,880 ****
--- 940,952 ----
      virBufferFree(buf);
      return(ret);
  }
+ 
+ 
+ /*
+  * Local variables:
+  *  indent-tabs-mode: nil
+  *  c-indent-level: 4
+  *  c-basic-offset: 4
+  *  tab-width: 4
+  * End:
+  */
Index: src/conf.h
===================================================================
RCS file: /data/cvs/libvirt/src/conf.h,v
retrieving revision 1.1
diff -c -r1.1 conf.h
*** src/conf.h	29 Aug 2006 22:27:07 -0000	1.1
--- src/conf.h	15 Nov 2006 02:33:59 -0000
***************
*** 50,55 ****
--- 50,56 ----
  typedef struct _virConf virConf;
  typedef virConf *virConfPtr;
  
+ virConfPtr      virConfNew              (void);
  virConfPtr	virConfReadFile		(const char *filename);
  virConfPtr	virConfReadMem		(const char *memory,
  					 int len);
***************
*** 57,62 ****
--- 58,66 ----
  
  virConfValuePtr	virConfGetValue		(virConfPtr conf,
  					 const char *setting);
+ int             virConfSetValue         (virConfPtr conf,
+ 					 const char *setting,
+ 					 virConfValuePtr value);
  int		virConfWriteFile	(const char *filename,
  					 virConfPtr conf);
  int		virConfWriteMem		(char *memory,

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