00001 /** @file include/dmlite/c/pool.h 00002 * @brief C wrapper for DMLite Pool API. 00003 * @author Alejandro Álvarez Ayllon <aalvarez@cern.ch> 00004 */ 00005 #ifndef DMLITE_POOL_H 00006 #define DMLITE_POOL_H 00007 00008 #include "dmlite.h" 00009 #include "any.h" 00010 #include "inode.h" 00011 #include "utils.h" 00012 00013 #define POOL_TYPE_MAX 16 00014 #define POOL_MAX 16 00015 00016 #ifdef __cplusplus 00017 extern "C" { 00018 #endif 00019 00020 /** @brief Pool data */ 00021 typedef struct dmlite_pool { 00022 char pool_type[POOL_TYPE_MAX]; 00023 char pool_name[POOL_MAX]; 00024 00025 dmlite_any_dict* extra; 00026 } dmlite_pool; 00027 00028 /** @brief Chunk of data */ 00029 typedef struct dmlite_chunk { 00030 off_t offset; 00031 size_t size; 00032 dmlite_url url; 00033 } dmlite_chunk; 00034 00035 /** @brief Collection of chunks that form a replica 00036 * @details On read, there may be duplicated chunks. 00037 */ 00038 typedef struct dmlite_location { 00039 dmlite_chunk* chunks; 00040 unsigned nchunks; 00041 } dmlite_location; 00042 00043 /** 00044 * @brief Gets the list of pools. 00045 * @param context The DM context. 00046 * @param nPools The number of pools. 00047 * @param pools An array with the pools. <b>Use dmlite_freepools to free</b>. 00048 * @return 0 on success, error code otherwise. 00049 */ 00050 int dmlite_getpools(dmlite_context* context, unsigned* nPools, dmlite_pool** pools); 00051 00052 /** 00053 * @brief Frees an array of pools. 00054 * @param nPools The number of pools in the array. 00055 * @param pools The array to free. 00056 * @return 0 on success, error code otherwise. 00057 */ 00058 int dmlite_pools_free(unsigned nPools, dmlite_pool* pools); 00059 00060 /** 00061 * @brief Gets a single replica (synchronous). 00062 * @param context The DM context. 00063 * @param path The logical file name. 00064 * @return A pointer to a dmlite_location struct, or NULL on error. 00065 */ 00066 dmlite_location* dmlite_get(dmlite_context* context, const char* path); 00067 00068 /** 00069 * @brief Gets a single replica (synchronous). 00070 * @param context The DM context. 00071 * @param inode The file inode. 00072 * @return A pointer to a dmlite_location struct, or NULL on error. 00073 */ 00074 dmlite_location* dmlite_iget(dmlite_context* context, ino_t inode); 00075 00076 /** 00077 * @brief Gets the location of a replica. 00078 * @param context The DM context. 00079 * @param replica The replica to translate. 00080 * @return A pointer to a dmlite_location struct, or NULL on error. 00081 */ 00082 dmlite_location* dmlite_getlocation(dmlite_context* context, const dmlite_replica* replica); 00083 00084 /** 00085 * @brief Puts a file (synchronous). 00086 * @param context The DM context. 00087 * @param path The logical file name to put. 00088 * @return A pointer to a dmlite_location struct, or NULL on error. 00089 */ 00090 dmlite_location* dmlite_put(dmlite_context* context, const char* path); 00091 00092 /** 00093 * @brief Aborts a put request. 00094 * @param context The DM context. 00095 * @param loc As returned by dmlite_put. 00096 * @return 0 on success, error code otherwise. 00097 */ 00098 int dmlite_put_abort(dmlite_context* context, const dmlite_location* loc); 00099 00100 /** 00101 * @brief Frees a location struct. 00102 * @param loc The struct to free. 00103 * @return 0 on success, error code otherwise. 00104 */ 00105 int dmlite_location_free(dmlite_location* loc); 00106 00107 /** 00108 * @brief Get the estimation of the free/used space for writing into a directory 00109 * @param path The path of the directory to query 00110 * @param totalfree The total number of free bytes (may not be contiguous) 00111 * @param used The total number of used bytes 00112 * @return 0 on success, error code otherwise. 00113 */ 00114 int dmlite_getdirspaces(dmlite_context* context, const char *logicaldir, int64_t *freespace, int64_t *used); 00115 00116 00117 #ifdef __cplusplus 00118 } 00119 #endif 00120 00121 #endif /* DMLITE_POOL_H */