nfs-ganesha 1.4
|
00001 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil; -*- 00002 * vim:expandtab:shiftwidth=4:tabstop=4: 00003 */ 00004 #ifdef HAVE_CONFIG_H 00005 #include "config.h" 00006 #endif 00007 #include "posixdb_internal.h" 00008 #include <string.h> 00009 00010 fsal_posixdb_status_t fsal_posixdb_delete(fsal_posixdb_conn * p_conn, /* IN */ 00011 posixfsal_handle_t * p_parent_directory_handle, /* IN */ 00012 fsal_name_t * p_filename, /* IN */ 00013 fsal_posixdb_fileinfo_t * 00014 p_object_info /* IN */ ) 00015 { 00016 result_handle_t res; 00017 fsal_posixdb_status_t st; 00018 char query[2048]; 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 BeginTransaction(p_conn); 00028 00029 /******************************* 00030 * 2/ we check the file exists * 00031 *******************************/ 00032 00033 snprintf(query, 2048, "SELECT Parent.handleid, Parent.handlets, " 00034 "Handle.deviceid, Handle.inode, Handle.nlink, Handle.ctime, Handle.ftype " 00035 "FROM Parent INNER JOIN Handle ON Parent.handleid = Handle.handleid " 00036 "AND Parent.handlets=Handle.handlets " 00037 "WHERE handleidparent=%llu AND handletsparent=%u AND name='%s' " 00038 "FOR UPDATE", p_parent_directory_handle->data.id, 00039 p_parent_directory_handle->data.ts, p_filename->name); 00040 00041 st = db_exec_sql(p_conn, query, &res); 00042 if(FSAL_POSIXDB_IS_ERROR(st)) 00043 goto rollback; 00044 00045 if(mysql_num_rows(res) != 1) 00046 { 00047 /* parent entry not found */ 00048 mysql_free_result(res); 00049 RollbackTransaction(p_conn); 00050 ReturnCodeDB(ERR_FSAL_POSIXDB_NOENT, 0); 00051 } 00052 mysql_free_result(res); 00053 00054 /*********************************************** 00055 * 3/ Get information about the file to delete * 00056 ***********************************************/ 00057 00058 st = fsal_posixdb_internal_delete(p_conn, p_parent_directory_handle->data.id, 00059 p_parent_directory_handle->data.ts, 00060 p_filename->name, p_object_info); 00061 if(FSAL_POSIXDB_IS_ERROR(st)) 00062 goto rollback; 00063 00064 return EndTransaction(p_conn); 00065 00066 rollback: 00067 RollbackTransaction(p_conn); 00068 return st; 00069 } 00070 00071 fsal_posixdb_status_t fsal_posixdb_deleteHandle(fsal_posixdb_conn * p_conn, /* IN */ 00072 posixfsal_handle_t * 00073 p_parent_directory_handle /* IN */ ) 00074 { 00075 /* char handleid_str[MAX_HANDLEIDSTR_SIZE]; 00076 char handlets_str[MAX_HANDLETSSTR_SIZE]; 00077 const char *paramValues[2]; */ 00078 int found; 00079 result_handle_t res; 00080 fsal_posixdb_status_t st; 00081 char query[2048]; 00082 00083 BeginTransaction(p_conn); 00084 00085 LogFullDebug(COMPONENT_FSAL, "Deleting %llu.%u\n", p_parent_directory_handle->data.id, 00086 p_parent_directory_handle->data.ts); 00087 00088 snprintf(query, 2048, 00089 "SELECT Handle.deviceid, Handle.inode, Handle.nlink, Handle.ctime, Handle.ftype " 00090 "FROM Handle WHERE handleid=%llu AND handlets=%u FOR UPDATE", 00091 p_parent_directory_handle->data.id, p_parent_directory_handle->data.ts); 00092 00093 st = db_exec_sql(p_conn, query, &res); 00094 if(FSAL_POSIXDB_IS_ERROR(st)) 00095 goto rollback; 00096 00097 found = mysql_num_rows(res); 00098 mysql_free_result(res); 00099 00100 if(found) 00101 { 00102 /* entry found */ 00103 st = fsal_posixdb_recursiveDelete(p_conn, p_parent_directory_handle->data.id, 00104 p_parent_directory_handle->data.ts, FSAL_TYPE_DIR); 00105 if(FSAL_POSIXDB_IS_ERROR(st)) 00106 goto rollback; 00107 } 00108 00109 return EndTransaction(p_conn); 00110 00111 rollback: 00112 RollbackTransaction(p_conn); 00113 return st; 00114 00115 }