summaryrefslogtreecommitdiff
path: root/src/common/unionfs.c
diff options
context:
space:
mode:
authorAn-Cheng Huang <ancheng@vyatta.com>2011-03-02 18:53:27 -0800
committerAn-Cheng Huang <ancheng@vyatta.com>2011-03-02 18:53:27 -0800
commit92a6e0844ffd1614eb30ae093d3e6e7e5540321f (patch)
treebd5e3aea16606d248cd010a7a3b3c883907d2af1 /src/common/unionfs.c
parent521e99d155759a80b2b97c6d5b827d490426c0b6 (diff)
downloadvyatta-cfg-92a6e0844ffd1614eb30ae093d3e6e7e5540321f.tar.gz
vyatta-cfg-92a6e0844ffd1614eb30ae093d3e6e7e5540321f.zip
clean up commit dead code etc. etc. etc.
Diffstat (limited to 'src/common/unionfs.c')
-rw-r--r--src/common/unionfs.c225
1 files changed, 115 insertions, 110 deletions
diff --git a/src/common/unionfs.c b/src/common/unionfs.c
index 6646e74..e9266cc 100644
--- a/src/common/unionfs.c
+++ b/src/common/unionfs.c
@@ -106,28 +106,18 @@ static void
piecewise_copy(GNode *root_node, boolean test_mode);
/**
+ * Data is stored on the path:
+ * <newcfgroot>/system/login/user/foo/authentication/plaintext-password
*
+ * Template is stored along this path:
+ * <tmplroot>/system/login/user/node.tag/authentication/plaintext-password
*
- Data is stored on the path:
-
- /opt/vyatta/config/tmp/new_config_5425/system/login/user/foo/authentication/plaintext-password
-
- Config is stored along this path:
-
- /opt/vyatta/config/template/vyatta-cfg/system/login/user/node.tag/authentication/plaintext-password
-
- 1) Need to split out relative path
-
- 2) if node is *MULTI* then the path value is the actual value
-
- 3) For the config copy the pointer from an existing config value for each multinode
-<Need to figure out how this is going to happen>
-
-This should allow a combined data/config tree
-
- *
- *
+ * 1) Need to split out relative path
+ * 2) if node is *MULTI* then the path value is the actual value
+ * 3) For the config copy the pointer from an existing config value for each
+ * multinode <Need to figure out how this is going to happen>
*
+ * This should allow a combined data/config tree
**/
char*
get_config_path(GNode *node)
@@ -156,7 +146,9 @@ get_config_path(GNode *node)
char tmp[MAX_LENGTH_DIR_PATH];
strcpy(tmp,buf);
- //need to check the configuration location for the existance of this node to determine if it's a multi
+ /* need to check the configuration location for the existance of
+ * this node to determine if it's a multi
+ */
if (G_NODE_IS_ROOT(n->parent) != TRUE &&
((struct VyattaNode*)(n->parent->data))->_config._multi == TRUE) {
sprintf(buf,"node.tag/%s",tmp);
@@ -258,7 +250,9 @@ retrieve_data(char* rel_data_path, GNode *node, const char* root,
syslog(LOG_DEBUG,"[FOUND node.def]");
}
- //either multi or tag--shouldn't have made a difference, but arkady was confused.
+ /* either multi or tag--shouldn't have made a difference, but arkady
+ * was confused.
+ */
vn->_config._multi = (def.tag | def.multi);
if (def.def_tag != 0) {
vn->_config._limit = def.def_tag;
@@ -290,24 +284,32 @@ retrieve_data(char* rel_data_path, GNode *node, const char* root,
if (vn_parent->_config._multi == TRUE) {
((struct VyattaNode*)node->data)->_data._value = TRUE;
- //patch up to preserve multinode behavior on value node, can also put node.def on node.tag with priority
- //Need to do two things:
- // 1. Come to agreement on where the behavior splits on priority multinodes
- // 2. Not check for tag node in the def datastructure but use the new datastructure as at some point tag and multi will be the same
+ /* patch up to preserve multinode behavior on value node, can also
+ * put node.def on node.tag with priority
+ * Need to do two things:
+ * 1. Come to agreement on where the behavior splits on priority
+ * multinodes
+ * 2. Not check for tag node in the def datastructure but use the
+ * new datastructure as at some point tag and multi will be the
+ * same
+ */
//now let's patch up the def multi-nodes
//move the def for the multinode from the parent to the value node
struct VyattaNode* vn2 = (struct VyattaNode*)node->data;
if (final_node == FALSE) { //non-term multi
if (g_node_n_children(node->parent) == 1) {
- vn2->_config._def = ((struct VyattaNode*)node->parent->data)->_config._def;
- memset(&((struct VyattaNode*)node->parent->data)->_config._def, 0, sizeof(vtw_def));
+ vn2->_config._def
+ = ((struct VyattaNode*)node->parent->data)->_config._def;
+ memset(&((struct VyattaNode*)node->parent->data)->_config._def,
+ 0, sizeof(vtw_def));
}
else { //find node other than myself to copy defs across
GNode *first_child = g_node_first_child(node->parent);
if (first_child == node) {
first_child = g_node_next_sibling(first_child);
}
- vn2->_config._def = ((struct VyattaNode*)first_child->data)->_config._def;
+ vn2->_config._def
+ = ((struct VyattaNode*)first_child->data)->_config._def;
}
}
}
@@ -339,9 +341,6 @@ retrieve_data(char* rel_data_path, GNode *node, const char* root,
}
}
-
-
-
if (final_node == TRUE) {
//move defs to child...
get_term_data_values(node);
@@ -362,13 +361,16 @@ retrieve_data(char* rel_data_path, GNode *node, const char* root,
if ((dp = opendir(full_data_path)) == NULL){
if (g_debug) {
//could also be a terminating value now
- printf("unionfs::retrieve_data(), failed to open directory: %s\n", full_data_path);
- syslog(LOG_DEBUG,"unionfs::retrieve_data(), failed to open directory: %s\n", full_data_path);
+ printf("unionfs::retrieve_data(), failed to open directory: %s\n",
+ full_data_path);
+ syslog(LOG_DEBUG,
+ "unionfs::retrieve_data(), failed to open directory: %s\n",
+ full_data_path);
}
return;
}
- //finally iterate over valid child directory entries
+ //finally iterate over valid child directory entries
boolean processed = FALSE;
boolean whiteout_file_found = FALSE;
struct dirent *dirp = NULL;
@@ -388,7 +390,9 @@ retrieve_data(char* rel_data_path, GNode *node, const char* root,
processed = TRUE;
NODE_ACTIVATE deactivated = K_NO_DISABLE_OP;
- if (G_NODE_IS_ROOT(node) == FALSE && ((struct VyattaNode*)node->data)->_data._disable_op != K_NO_DISABLE_OP) {
+ if (G_NODE_IS_ROOT(node) == FALSE
+ && ((struct VyattaNode*)node->data)->_data._disable_op
+ != K_NO_DISABLE_OP) {
deactivated = ((struct VyattaNode*)node->data)->_data._disable_op;
}
else { //do a lstat check in the local dir
@@ -404,18 +408,21 @@ retrieve_data(char* rel_data_path, GNode *node, const char* root,
char buf[MAX_LENGTH_HELP_STR];
- sprintf(buf,"%s/%s/%s/%s",get_mdirp(),rel_data_path,namebuf,DISABLE_FILE);
+ sprintf(buf, "%s/%s/%s/%s", get_mdirp(), rel_data_path, namebuf,
+ DISABLE_FILE);
if (lstat(buf,&s) == 0) {
- //need to check existence of file in active configuration here as well!
+ /* need to check existence of file in active configuration here
+ * as well!
+ */
deactivated |= K_LOCAL_DISABLE_OP;
}
- sprintf(buf,"%s/%s/%s/%s",get_adirp(),rel_data_path,namebuf,DISABLE_FILE);
+ sprintf(buf, "%s/%s/%s/%s", get_adirp(), rel_data_path, namebuf,
+ DISABLE_FILE);
if (lstat(buf,&s) == 0) {
deactivated |= K_ACTIVE_DISABLE_OP;
}
}
- // char *data_buf = malloc(MAX_LENGTH_DIR_PATH*sizeof(char));
char *data_buf = malloc(strlen(dirp->d_name)+5);
if (strncmp(dirp->d_name,DELETED_NODE,4) == 0) {
struct VyattaNode *vn = calloc(1,sizeof(struct VyattaNode));
@@ -438,10 +445,11 @@ retrieve_data(char* rel_data_path, GNode *node, const char* root,
sprintf(new_data_path,"%s/%s",rel_data_path,data_buf);
GNode *new_node = g_node_new(vn);
- // new_node = g_node_insert(node, -1, new_node);
new_node = insert_sibling_in_order(node,new_node);
- //will need to enter a special recursion against the active configuration to mark nested delete nodes
+ /* will need to enter a special recursion against the active
+ * configuration to mark nested delete nodes
+ */
retrieve_data(new_data_path,new_node,get_adirp(),K_DEL_OP);
}
else if (deactivated != K_NO_DISABLE_OP) {
@@ -466,11 +474,13 @@ retrieve_data(char* rel_data_path, GNode *node, const char* root,
sprintf(new_data_path,"%s/%s",rel_data_path,data_buf);
GNode *new_node = g_node_new(vn);
- // new_node = g_node_insert(node, -1, new_node);
new_node = insert_sibling_in_order(node,new_node);
- //will need to enter a special recursion against the active configuration to mark nested delete nodes
- retrieve_data(new_data_path,new_node,get_adirp(),vn->_data._operation);
+ /* will need to enter a special recursion against the active
+ * configuration to mark nested delete nodes
+ */
+ retrieve_data(new_data_path, new_node, get_adirp(),
+ vn->_data._operation);
}
else {
strcpy(data_buf,dirp->d_name);
@@ -500,10 +510,10 @@ retrieve_data(char* rel_data_path, GNode *node, const char* root,
vn->_data._operation = K_DEL_OP;
}
GNode *new_node = g_node_new(vn);
- // new_node = g_node_insert(node, -1, new_node);
new_node = insert_sibling_in_order(node,new_node);
if (op == K_DEL_OP || vn->_data._disable_op != K_NO_DISABLE_OP) {
- retrieve_data(new_data_path,new_node,get_adirp(),vn->_data._operation);
+ retrieve_data(new_data_path, new_node, get_adirp(),
+ vn->_data._operation);
}
else {
retrieve_data(new_data_path,new_node,root,vn->_data._operation);
@@ -522,8 +532,9 @@ retrieve_data(char* rel_data_path, GNode *node, const char* root,
}
closedir(dp);
- //if there is a ".wh.__dir_opaque" and were not already
- //iterating the active dir then test for a hidden deletion
+ /* if there is a ".wh.__dir_opaque" and were not already
+ * iterating the active dir then test for a hidden deletion
+ */
if (whiteout_file_found == TRUE && op != K_DEL_OP) {
//scan active dir for entry not found in tmp
DIR *dp_wo;
@@ -533,13 +544,17 @@ retrieve_data(char* rel_data_path, GNode *node, const char* root,
if ((dp_wo = opendir(active_data_path)) != NULL) {
if (g_debug) {
//could also be a terminating value now
- syslog(LOG_DEBUG,"unionfs::retrieve_data(), failed to open directory: %s\n", active_data_path);
- printf("unionfs::retrieve_data(), failed to open directory: %s\n", active_data_path);
+ syslog(LOG_DEBUG,
+ "unionfs::retrieve_data(), failed to open directory: %s\n",
+ active_data_path);
+ printf("unionfs::retrieve_data(), failed to open directory: %s\n",
+ active_data_path);
}
struct dirent *dirp_wo = NULL;
while ((dirp_wo = readdir(dp_wo)) != NULL) {
char tmp_new_data_path[MAX_LENGTH_DIR_PATH];
- sprintf(tmp_new_data_path,"%s/%s/%s",get_cdirp(),rel_data_path,dirp_wo->d_name);
+ sprintf(tmp_new_data_path, "%s/%s/%s", get_cdirp(), rel_data_path,
+ dirp_wo->d_name);
struct stat s;
if (lstat(tmp_new_data_path,&s) != 0) {
//create new node and insert...
@@ -585,11 +600,11 @@ common_get_local_session_data()
//create first node
GNode *root_node = g_node_new(vn);
- //iterate through recursive calls to parse_new() calls (see original commit())
+ /* iterate through recursive calls to parse_new() calls (see original
+ * commit())
+ */
retrieve_data(data_path,root_node,get_cdirp(),K_SET_OP);
- // apply_priority(root_node);
-
return root_node;
}
@@ -615,7 +630,8 @@ common_set_parent_context(char *cpath, char *dpath)
{
if (g_debug) {
printf("common_set_parent_context(incoming): %s, %s\n",cpath,dpath);
- syslog(LOG_DEBUG,"common_set_parent_context(incoming): %s, %s\n",cpath,dpath);
+ syslog(LOG_DEBUG, "common_set_parent_context(incoming): %s, %s\n",
+ cpath, dpath);
}
//strip off last path and set
int index = strlen(cpath)-1;
@@ -703,16 +719,6 @@ set_path(char *path, boolean config)
int size = end_ptr-start_ptr;
if (size < 1 || size > 1024) {
- /*
- if (g_debug) {
- if (config == FALSE) {
- printf("unionfs::set_path(): %s, %s\n", path,m_path.path);
- }
- else {
- printf("unionfs::set_path(): %s, %s\n", path,t_path.path);
- }
- }
- */
return;
}
@@ -727,16 +733,6 @@ set_path(char *path, boolean config)
}
start_ptr = end_ptr;
}
- /*
- if (g_debug) {
- if (config == FALSE) {
- printf("unionfs::set_path(): %s, %s\n", path,m_path.path);
- }
- else {
- printf("unionfs::set_path(): %s, %s\n", path,t_path.path);
- }
- }
- */
}
/**
@@ -746,7 +742,8 @@ set_path(char *path, boolean config)
*
**/
void
-common_commit_copy_to_live_config(GNode *node, boolean suppress_piecewise_copy, boolean test_mode)
+common_commit_copy_to_live_config(GNode *node, boolean suppress_piecewise_copy,
+ boolean test_mode)
{
//first check for existence of path before committing
char *path = ((struct VyattaNode*)(node->data))->_data._path;
@@ -891,8 +888,6 @@ common_commit_clean_temp_config(GNode *root_node, boolean test_mode)
printf("common_commit_clean_temp_config()\n");
syslog(LOG_DEBUG,"common_commit_clean_temp_config()\n");
}
- //first clean up the root
- // common_commit_copy_to_live_config("/");
char *command;
command = malloc(MAX_LENGTH_DIR_PATH);
@@ -915,11 +910,14 @@ common_commit_clean_temp_config(GNode *root_node, boolean test_mode)
/*
* Need to add to the following func below to clean up dangling .wh. files.
* This pass needs to be prior to the commands below (but after the umount).
- * This fixes a bug when higher priority root nodes are deleted and not removed.
+ * This fixes a bug when higher priority root nodes are deleted and not
+ * removed.
*/
- //Iterate through node hierarchy and remove deleted nodes from active config--insurance
- //to protect against priority whiteouts in parent/child order
+ /* Iterate through node hierarchy and remove deleted nodes from active
+ * config--insurance to protect against priority whiteouts in parent/child
+ * order
+ */
//TOP DOWN
if (root_node != NULL) {
struct SrcDst sd;
@@ -980,7 +978,6 @@ copy_vyatta_node(struct VyattaNode* vn)
new_vn->_config._multi = vn->_config._multi;
new_vn->_config._priority = vn->_config._priority;
new_vn->_config._priority_extended = vn->_config._priority_extended;
- // new_vn->_config._def = new_vn->_config._def; //cpy this?
if (vn->_config._default != NULL) {
new_vn->_config._default = malloc(strlen(vn->_config._default)+1);
strcpy(new_vn->_config._default,vn->_config._default);
@@ -1022,7 +1019,6 @@ get_term_data_values(GNode *node)
tok_str_active = g_strsplit(cp,"\n",0);
}
-
init_path(&vpath, full_new_data_path);
if (value_exists(full_new_data_path) && get_value(&cp, &vpath) == 0) {
tok_str_new = g_strsplit(cp,"\n",0);
@@ -1060,7 +1056,8 @@ get_term_data_values(GNode *node)
(tok_str_new == NULL || tok_str_new[0] == NULL)) {
cp = malloc(sizeof(char));
cp[0] = '\0';
- data->_state = ((struct VyattaNode*)node->parent->data)->_data._operation;
+ data->_state
+ = ((struct VyattaNode*)node->parent->data)->_data._operation;
g_datalist_set_data(&datalist, cp, data);
}
else if (tok_str_active == NULL || tok_str_active[0] == NULL) {
@@ -1091,9 +1088,6 @@ get_term_data_values(GNode *node)
g_strfreev(tok_str_new);
g_strfreev(tok_str_active);
-
- // g_dataset_destroy(&datalist);
-
}
/**
@@ -1115,9 +1109,7 @@ dlist_test_func(GQuark key_id,gpointer data,gpointer user_data)
if (vn->_data._value == TRUE) {
new_vn = copy_vyatta_node(vn);
GNode *new_node = g_node_new(new_vn);
- // g_node_insert(node, -1, new_node);
g_node_insert_after(node, NULL, new_node);
- // insert_sibling_in_order(node,new_node);
new_vn->_config._def = vn->_config._def;
}
else {
@@ -1125,7 +1117,6 @@ dlist_test_func(GQuark key_id,gpointer data,gpointer user_data)
char buf[MAX_LENGTH_DIR_PATH];
strcpy(buf,new_vn->_data._path);
- // new_vn->_data._path = (char*)realloc(new_vn->_data._path,sizeof(new_vn->_data._path)+8);
strcat(buf,"/value:");
if (vn_parent->_config._def.multi == FALSE) {
char *tmp = (char*)g_quark_to_string(key_id);
@@ -1153,7 +1144,7 @@ dlist_test_func(GQuark key_id,gpointer data,gpointer user_data)
new_vn->_config._path = malloc(strlen(vn_parent->_config._path)+10);
sprintf(new_vn->_config._path,"%s/node.tag",vn_parent->_config._path);
- //let's set this nodes disable_op to its parent's value.
+ // let's set this nodes disable_op to its parent's value.
new_vn->_data._disable_op = vn_parent->_data._disable_op;
new_vn->_data._operation = ((struct ValueData*)data)->_state;
@@ -1170,7 +1161,8 @@ insert_sibling_in_order(GNode *parent, GNode *child)
//find alphabetical order to insert child into sibling
GNode *sibling = parent->children;
while (sibling != NULL) {
- if (strcmp((((struct VyattaNode*)(child->data))->_data._name),((struct VyattaNode*)(sibling->data))->_data._name) > 0) {
+ if (strcmp(((struct VyattaNode*)(child->data))->_data._name,
+ ((struct VyattaNode*)(sibling->data))->_data._name) > 0) {
break;
}
sibling = sibling->next;
@@ -1233,10 +1225,15 @@ copy_func(GNode *node, gpointer data)
//THIS IS ONLY FOR NODE.VAL (or leafs, term multis)
- //before copy also need to clear out def file in active directory (will copy over current if found)
- //this is for the case where it is set by default, then unset at the node--i.e. no longer a default value.
- if (((struct VyattaNode*)(node->data))->_config._multi == FALSE) { //only for leaf
- char *parent_path = ((struct VyattaNode*)(node->parent->data))->_data._path;
+ /* before copy also need to clear out def file in active directory
+ * (will copy over current if found)
+ * this is for the case where it is set by default, then unset at the
+ * node--i.e. no longer a default value.
+ */
+ if (((struct VyattaNode*)(node->data))->_config._multi == FALSE) {
+ //only for leaf
+ char *parent_path
+ = ((struct VyattaNode*)(node->parent->data))->_data._path;
if (g_debug) {
printf("rm %s%sdef\n", sd->_dst, parent_path);
syslog(LOG_DEBUG, "rm %s%sdef", sd->_dst, parent_path);
@@ -1308,18 +1305,19 @@ delete_func(GNode *node, gpointer data)
char *command = malloc(MAX_LENGTH_DIR_PATH);
//DONT HAVE THE COMMAND BELOW BLOW AWAY WHITEOUT FILES!!!!!
- static const char format[]="rm -f '%s%s'{*,.*} >&/dev/null;rmdir %s%s >&/dev/null ; /bin/true"; //need to remove opaque file.
- static const char format_force_delete[]="rm -f '%s%s'{*,.*} >&/dev/null;rmdir %s%s >&/dev/null ; /bin/true"; //force delete as this is a delete operation with dependency
+ // need to remove opaque file.
+ static const char format[]
+ = "rm -f '%s%s'{*,.*} >&/dev/null;rmdir %s%s >&/dev/null ; /bin/true";
+ // force delete as this is a delete operation with dependency
+ static const char format_force_delete[]
+ = "rm -f '%s%s'{*,.*} >&/dev/null;rmdir %s%s >&/dev/null ; /bin/true";
static const char delete_format[]="rm %s%s../.wh.%s >&/dev/null";
char *path = ((struct VyattaNode*)(node->data))->_data._path;
//does this node have any children that have not been copied????
-
//NEED RM -FV on changes only directory!!!! for normal removal!!!
-
-
//WILL ONLY REMOVE DIRS WITHOUT CHILD DIRS--just what we want..
//NEED TO PREVENT THE COMMAND BELOW FROM DELETING WHITEOUT FILES....
@@ -1329,7 +1327,9 @@ delete_func(GNode *node, gpointer data)
}
- //DOESN'T QUITE FIX THE PROBLEM, THE PARENT IS CALLED (AND PROBABLY SHOULDN'T BE)
+ /* DOESN'T QUITE FIX THE PROBLEM, THE PARENT IS CALLED (AND PROBABLY
+ * SHOULDN'T BE)
+ */
if (!IS_DELETE(((struct VyattaNode*)(node->data))->_data._operation)) {
sprintf(command,format,sd->_src,path,sd->_src,path);
if (g_debug) {
@@ -1346,10 +1346,12 @@ delete_func(GNode *node, gpointer data)
if (IS_DELETE(((struct VyattaNode*)(node->data))->_data._operation) &&
!IS_ACTIVE(((struct VyattaNode*)(node->data))->_data._operation)) {
- //DO NOT PERFORM THIS STEP IF THERE ARE SUBDIRECTORIES (only the whiteout file)
-
+ /* DO NOT PERFORM THIS STEP IF THERE ARE SUBDIRECTORIES (only the
+ * whiteout file)
+ */
//remove .whiteout file in c directory if encountered in walk.
- sprintf(command,delete_format,sd->_src,path,((struct VyattaNode*)(node->data))->_data._name);
+ sprintf(command, delete_format, sd->_src, path,
+ ((struct VyattaNode*)(node->data))->_data._name);
if (g_debug) {
printf("%s\n",command);
syslog(LOG_DEBUG,"%s\n",command);
@@ -1392,12 +1394,15 @@ delete_wh_func(GNode *node, gpointer data)
GNode *parent_node = node->parent;
- //on node where operation is delete and parent is noop or active then remove directory from active config
- //if this is a deletion operation, need to remove
+ /* on node where operation is delete and parent is noop or active then
+ * remove directory from active config
+ * if this is a deletion operation, need to remove
+ */
if (parent_node != NULL) {
- if (IS_DELETE(((struct VyattaNode*)(node->data))->_data._operation) &&
- !IS_ACTIVE(((struct VyattaNode*)(node->data))->_data._operation) &&
- !IS_DELETE(((struct VyattaNode*)(parent_node->data))->_data._operation)) {
+ NODE_OPERATION op = ((struct VyattaNode*)(node->data))->_data._operation;
+ NODE_OPERATION pop
+ = ((struct VyattaNode*)(parent_node->data))->_data._operation;
+ if (IS_DELETE(op) && !IS_ACTIVE(op) && !IS_DELETE(pop)) {
char *path = ((struct VyattaNode*)(node->data))->_data._path;
sprintf(abuf,"%s%s",get_adirp(),path);