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 #define CHUNK_ID_MAX 16 00016 #define CHUNK_URL_ALT_MAX 512 00017 00018 #ifdef __cplusplus 00019 extern "C" { 00020 #endif 00021 00022 /** @brief Pool data */ 00023 typedef struct dmlite_pool { 00024 char pool_type[POOL_TYPE_MAX]; 00025 char pool_name[POOL_MAX]; 00026 00027 dmlite_any_dict* extra; 00028 } dmlite_pool; 00029 00030 /** @brief Chunk of data */ 00031 typedef struct dmlite_chunk { 00032 off_t offset; 00033 size_t size; 00034 char url_alt[CHUNK_URL_ALT_MAX]; 00035 char chunkid[CHUNK_ID_MAX]; 00036 dmlite_url url; 00037 } dmlite_chunk; 00038 00039 /** @brief Collection of chunks that form a replica 00040 * @details On read, there may be duplicated chunks. 00041 */ 00042 typedef struct dmlite_location { 00043 dmlite_chunk* chunks; 00044 unsigned nchunks; 00045 } dmlite_location; 00046 00047 /** 00048 * @brief Gets the list of pools. 00049 * @param context The DM context. 00050 * @param nPools The number of pools. 00051 * @param pools An array with the pools. <b>Use dmlite_freepools to free</b>. 00052 * @return 0 on success, error code otherwise. 00053 */ 00054 int dmlite_getpools(dmlite_context* context, unsigned* nPools, dmlite_pool** pools); 00055 00056 /** 00057 * @brief Frees an array of pools. 00058 * @param nPools The number of pools in the array. 00059 * @param pools The array to free. 00060 * @return 0 on success, error code otherwise. 00061 */ 00062 int dmlite_pools_free(unsigned nPools, dmlite_pool* pools); 00063 00064 /** 00065 * @brief Gets a single replica (synchronous). 00066 * @param context The DM context. 00067 * @param path The logical file name. 00068 * @return A pointer to a dmlite_location struct, or NULL on error. 00069 */ 00070 dmlite_location* dmlite_get(dmlite_context* context, const char* path); 00071 00072 /** @brief Progress markers for file copies. FTS jargon calls these "FTS performance markers" */ 00073 typedef struct dmlite_xferinfo { 00074 00075 // These are the performance markers to be passes 00076 time_t timestamp; 00077 int stripeindex; 00078 int64_t stripexferred; 00079 int totstripecount; 00080 00081 // Other fields I have no idea, the ones from FTS look weird to me 00082 } dmlite_xferinfo; 00083 00084 /** 00085 * @brief Copy a file to a remote location (synchronous). 00086 * @param context The DM context. 00087 * @param path The logical file name. 00088 * @param dest An URL, that must be a remote destination 00089 * @param cksumcheck Tell the copy process to check the final checksums 00090 * @param cksumtype Type of checksum that must be checked (e.g. adler32) 00091 * @return 0 on success, error code otherwise. EAGAIN means performance marker 00092 * 00093 * Beware, the path to the delegated proxy (if any) is stored in the dmlite context 00094 */ 00095 int dmlite_copypush(dmlite_context* context, const char* path, const char* dest, int cksumcheck, char *cksumtype, dmlite_xferinfo *progressdata); 00096 00097 /** 00098 * @brief Copy a file from a remote location (synchronous). 00099 * Allows copying to this head node, may add a replica to an 00100 * existing logical file entry 00101 * @param context The DM context. 00102 * @param path The logical file name. 00103 * @param source An URL, that may be a remote destination 00104 * @param cksumcheck Tell the copy process to check the final checksums 00105 * @param cksumtype Type of checksum that must be checked (e.g. adler32) 00106 * @return 0 on success, error code otherwise. EAGAIN means performance marker 00107 * 00108 * Beware, the path to the delegated proxy (if any) is stored in the dmlite context 00109 */ 00110 00111 int dmlite_copypull(dmlite_context* context, const char* path, const char* source, int cksumcheck, char *cksumtype, dmlite_xferinfo *progressdata); 00112 00113 /** 00114 * @brief Gets a single replica (synchronous). 00115 * @param context The DM context. 00116 * @param inode The file inode. 00117 * @return A pointer to a dmlite_location struct, or NULL on error. 00118 */ 00119 dmlite_location* dmlite_iget(dmlite_context* context, ino_t inode); 00120 00121 /** 00122 * @brief Gets the location of a replica. 00123 * @param context The DM context. 00124 * @param replica The replica to translate. 00125 * @return A pointer to a dmlite_location struct, or NULL on error. 00126 */ 00127 dmlite_location* dmlite_getlocation(dmlite_context* context, const dmlite_replica* replica); 00128 00129 /** 00130 * @brief Puts a file (synchronous). 00131 * @param context The DM context. 00132 * @param path The logical file name to put. 00133 * @return A pointer to a dmlite_location struct, or NULL on error. 00134 */ 00135 dmlite_location* dmlite_put(dmlite_context* context, const char* path); 00136 00137 /** 00138 * @brief Aborts a put request. 00139 * @param context The DM context. 00140 * @param loc As returned by dmlite_put. 00141 * @return 0 on success, error code otherwise. 00142 */ 00143 int dmlite_put_abort(dmlite_context* context, const dmlite_location* loc); 00144 00145 /** 00146 * @brief Frees a location struct. 00147 * @param loc The struct to free. 00148 * @return 0 on success, error code otherwise. 00149 */ 00150 int dmlite_location_free(dmlite_location* loc); 00151 00152 /** 00153 * @brief Get the estimation of the free/used space for writing into a directory 00154 * @param path The path of the directory to query 00155 * @param totalfree The total number of free bytes (may not be contiguous) 00156 * @param used The total number of used bytes 00157 * @return 0 on success, error code otherwise. 00158 */ 00159 int dmlite_getdirspaces(dmlite_context* context, const char *logicaldir, int64_t *freespace, int64_t *used); 00160 00161 00162 #ifdef __cplusplus 00163 } 00164 #endif 00165 00166 #endif /* DMLITE_POOL_H */