fsal_posixdb_status_t fsal_posixdb_deleteHandle(fsal_posixdb_conn * p_conn, /* IN */ posixfsal_handle_t * p_parent_directory_handle /* IN */ ) { /* char handleid_str[MAX_HANDLEIDSTR_SIZE]; char handlets_str[MAX_HANDLETSSTR_SIZE]; const char *paramValues[2]; */ int found; result_handle_t res; fsal_posixdb_status_t st; char query[2048]; BeginTransaction(p_conn); LogFullDebug(COMPONENT_FSAL, "Deleting %llu.%u\n", p_parent_directory_handle->data.id, p_parent_directory_handle->data.ts); snprintf(query, 2048, "SELECT Handle.deviceid, Handle.inode, Handle.nlink, Handle.ctime, Handle.ftype " "FROM Handle WHERE handleid=%llu AND handlets=%u FOR UPDATE", p_parent_directory_handle->data.id, p_parent_directory_handle->data.ts); st = db_exec_sql(p_conn, query, &res); if(FSAL_POSIXDB_IS_ERROR(st)) goto rollback; found = mysql_num_rows(res); mysql_free_result(res); if(found) { /* entry found */ st = fsal_posixdb_recursiveDelete(p_conn, p_parent_directory_handle->data.id, p_parent_directory_handle->data.ts, FSAL_TYPE_DIR); if(FSAL_POSIXDB_IS_ERROR(st)) goto rollback; } return EndTransaction(p_conn); rollback: RollbackTransaction(p_conn); return st; }
fsal_posixdb_status_t fsal_posixdb_internal_delete(fsal_posixdb_conn * p_conn, /* IN */ char *handleidparent_str, /* IN */ char *handletsparent_str, /* IN */ char *filename, /* IN */ fsal_posixdb_fileinfo_t * p_object_info /* IN */ ) { PGresult *p_res; char handleid_str[MAX_HANDLEIDSTR_SIZE]; char handlets_str[MAX_HANDLETSSTR_SIZE]; fsal_posixdb_status_t st; fsal_posixdb_fileinfo_t infodb; const char *paramValues[3]; if(!p_conn || !handleidparent_str || !handletsparent_str || !filename) ReturnCodeDB(ERR_FSAL_POSIXDB_FAULT, 0); paramValues[0] = handleidparent_str; paramValues[1] = handletsparent_str; paramValues[2] = filename; p_res = PQexecPrepared(p_conn, "lookupHandleByNameFU", 3, paramValues, NULL, NULL, 0); CheckResult(p_res); /* p_res contains : handleid, handlets, deviceId, inode, nlink, ctime, ftype */ /* no entry found */ if(PQntuples(p_res) != 1) { ReturnCodeDB(ERR_FSAL_POSIXDB_NOENT, 0); } strncpy(handleid_str, PQgetvalue(p_res, 0, 0), MAX_HANDLEIDSTR_SIZE); strncpy(handlets_str, PQgetvalue(p_res, 0, 1), MAX_HANDLETSSTR_SIZE); /* consistency check */ /* fill 'infodb' with information about the handle in the database */ posixdb_internal_fillFileinfoFromStrValues(&infodb, PQgetvalue(p_res, 0, 2), /* no need to compare inode & devid, they are the same */ PQgetvalue(p_res, 0, 3), PQgetvalue(p_res, 0, 4), /* nlink */ PQgetvalue(p_res, 0, 5), /* ctime */ PQgetvalue(p_res, 0, 6) /* ftype */ ); PQclear(p_res); if(p_object_info && fsal_posixdb_consistency_check(&infodb, p_object_info)) { /* not consistent, the bad handle have to be deleted */ LogCrit(COMPONENT_FSAL, "Consistency check failed while deleting a Path : Handle deleted"); infodb.ftype = FSAL_TYPE_DIR; /* considers that the entry is a directory in order to delete all its Parent entries and its Handle */ } switch (infodb.ftype) { case FSAL_TYPE_DIR: /* directory */ st = fsal_posixdb_recursiveDelete(p_conn, handleid_str, handlets_str, infodb.ftype); break; default: st = fsal_posixdb_deleteParent(p_conn, handleid_str, handlets_str, handleidparent_str, handletsparent_str, filename, infodb.nlink); } return st; }
fsal_posixdb_status_t fsal_posixdb_recursiveDelete(fsal_posixdb_conn * p_conn, char *handleid_str, char *handlets_str, fsal_nodetype_t ftype) { PGresult *p_res; fsal_posixdb_status_t st; fsal_nodetype_t ftype_tmp; unsigned int i; unsigned int i_max; const char *paramValues[2]; /* Sanity check */ if(!p_conn || !handleid_str || !handlets_str) { ReturnCodeDB(ERR_FSAL_POSIXDB_FAULT, 0); } if(ftype == FSAL_TYPE_DIR) { /* We find all the children of the directory in order to delete them, and then we delete the current handle */ paramValues[0] = handleid_str; paramValues[1] = handlets_str; p_res = PQexecPrepared(p_conn, "lookupChildrenFU", 2, paramValues, NULL, NULL, 0); CheckResult(p_res); i_max = (unsigned int)PQntuples(p_res); for(i = 0; i < i_max; i++) { ftype_tmp = (fsal_nodetype_t) atoi(PQgetvalue(p_res, i, 2)); if(ftype_tmp == FSAL_TYPE_DIR) { st = fsal_posixdb_recursiveDelete(p_conn, PQgetvalue(p_res, i, 0), PQgetvalue(p_res, i, 1), ftype_tmp); } else { st = fsal_posixdb_deleteParent(p_conn, PQgetvalue(p_res, i, 0), /* handleidparent */ PQgetvalue(p_res, i, 1), /* handletsparent */ handleid_str, handlets_str, PQgetvalue(p_res, i, 3), /* filename */ atoi(PQgetvalue(p_res, i, 4)) /* nlink */ ); } if(FSAL_POSIXDB_IS_ERROR(st)) { PQclear(p_res); return st; } } PQclear(p_res); } /* Delete the Handle */ /* All Parent entries having this handle will be deleted thanks to foreign keys */ paramValues[0] = handleid_str; paramValues[1] = handlets_str; /* invalidate name cache */ fsal_posixdb_InvalidateCache(); p_res = PQexecPrepared(p_conn, "deleteHandle", 2, paramValues, NULL, NULL, 0); CheckCommand(p_res); ReturnCodeDB(ERR_FSAL_POSIXDB_NOERR, 0); }