nfs-ganesha 1.4
|
00001 #ifdef HAVE_CONFIG_H 00002 #include "config.h" 00003 #endif 00004 00005 #include "posixdb_internal.h" 00006 #include <string.h> 00007 00008 fsal_posixdb_status_t fsal_posixdb_delete(fsal_posixdb_conn * p_conn, /* IN */ 00009 posixfsal_handle_t * p_parent_directory_handle, /* IN */ 00010 fsal_name_t * p_filename, /* IN */ 00011 fsal_posixdb_fileinfo_t * 00012 p_object_info /* IN */ ) 00013 { 00014 PGresult *p_res; 00015 char handleidparent_str[MAX_HANDLEIDSTR_SIZE] = { 0 }; 00016 char handletsparent_str[MAX_HANDLETSSTR_SIZE] = { 0 }; 00017 fsal_posixdb_status_t st; 00018 const char *paramValues[3]; 00019 00020 /******************* 00021 * 1/ sanity check * 00022 *******************/ 00023 00024 if(!p_conn || !p_parent_directory_handle || !p_filename) 00025 ReturnCodeDB(ERR_FSAL_POSIXDB_FAULT, 0); 00026 00027 CheckConn(p_conn); 00028 00029 BeginTransaction(p_conn, p_res); 00030 00031 /******************************* 00032 * 2/ we check the file exists * 00033 *******************************/ 00034 00035 snprintf(handleidparent_str, MAX_HANDLEIDSTR_SIZE, "%lli", 00036 p_parent_directory_handle->data.id); 00037 snprintf(handletsparent_str, MAX_HANDLETSSTR_SIZE, "%i", p_parent_directory_handle->data.ts); 00038 paramValues[0] = handleidparent_str; 00039 paramValues[1] = handletsparent_str; 00040 paramValues[2] = p_filename->name; 00041 p_res = PQexecPrepared(p_conn, "lookupHandleByNameFU", 3, paramValues, NULL, NULL, 0); 00042 CheckResult(p_res); 00043 00044 if(PQntuples(p_res) != 1) 00045 { 00046 /* parent entry not found */ 00047 RollbackTransaction(p_conn, p_res); 00048 ReturnCodeDB(ERR_FSAL_POSIXDB_NOENT, 0); 00049 } 00050 PQclear(p_res); 00051 00052 /*********************************************** 00053 * 3/ Get information about the file to delete * 00054 ***********************************************/ 00055 00056 st = fsal_posixdb_internal_delete(p_conn, handleidparent_str, handletsparent_str, 00057 p_filename->name, p_object_info); 00058 if(FSAL_POSIXDB_IS_ERROR(st)) 00059 { 00060 RollbackTransaction(p_conn, p_res); 00061 return st; 00062 } 00063 00064 EndTransaction(p_conn, p_res); 00065 00066 return st; 00067 } 00068 00069 fsal_posixdb_status_t fsal_posixdb_deleteHandle(fsal_posixdb_conn * p_conn, /* IN */ 00070 posixfsal_handle_t * 00071 p_parent_directory_handle /* IN */ ) 00072 { 00073 char handleid_str[MAX_HANDLEIDSTR_SIZE]; 00074 char handlets_str[MAX_HANDLETSSTR_SIZE]; 00075 const char *paramValues[2]; 00076 int found; 00077 PGresult *p_res; 00078 fsal_posixdb_status_t st; 00079 00080 CheckConn(p_conn); 00081 00082 BeginTransaction(p_conn, p_res); 00083 00084 LogFullDebug(COMPONENT_FSAL, "Deleting %lli.%i\n", p_parent_directory_handle->data.id, 00085 p_parent_directory_handle->data.ts); 00086 00087 snprintf(handleid_str, MAX_HANDLEIDSTR_SIZE, "%lli", p_parent_directory_handle->data.id); 00088 snprintf(handlets_str, MAX_HANDLETSSTR_SIZE, "%i", p_parent_directory_handle->data.ts); 00089 00090 paramValues[0] = handleid_str; 00091 paramValues[1] = handlets_str; 00092 p_res = PQexecPrepared(p_conn, "lookupHandleFU", 2, paramValues, NULL, NULL, 0); 00093 CheckResult(p_res); 00094 00095 found = PQntuples(p_res); 00096 PQclear(p_res); 00097 00098 if(found) 00099 { 00100 /* entry found */ 00101 st = fsal_posixdb_recursiveDelete(p_conn, handleid_str, handlets_str, 00102 FSAL_TYPE_DIR); 00103 if(FSAL_POSIXDB_IS_ERROR(st)) 00104 { 00105 RollbackTransaction(p_conn, p_res); 00106 return st; 00107 } 00108 } 00109 00110 EndTransaction(p_conn, p_res); 00111 00112 return st; 00113 }