2
* Copyright 1999-2006 University of Chicago
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
/******************************************************************************
21
Header of the GASS CACHE MANAGEMENT API.
25
$Source: /home/globdev/CVS/globus-packages/gass/cache/source/globus_gass_cache.h,v $
26
$Date: 2006/01/19 05:54:34 $
29
******************************************************************************/
30
#ifndef _GLOBUS_GASS_INCLUDE_GLOBUS_GASS_CACHE_H_
31
#define _GLOBUS_GASS_INCLUDE_GLOBUS_GASS_CACHE_H_
33
#ifndef EXTERN_C_BEGIN
35
#define EXTERN_C_BEGIN extern "C" {
36
#define EXTERN_C_END }
38
#define EXTERN_C_BEGIN
43
#include <sys/param.h>
45
#include "globus_common.h"
51
* Codes returned by globus_gass_cache module
54
#define GLOBUS_GASS_CACHE_ADD_NEW 1
55
#define GLOBUS_GASS_CACHE_URL_NOT_FOUND 2
56
#define GLOBUS_GASS_CACHE_ADD_EXISTS 3
58
#define GLOBUS_GASS_CACHE_ERROR_NO_HOME -1
59
#define GLOBUS_GASS_CACHE_ERROR_CAN_NOT_CREATE -2
60
#define GLOBUS_GASS_CACHE_ERROR_NAME_TOO_LONG -3
61
#define GLOBUS_GASS_CACHE_ERROR_LOCK_ERROR -4
62
/* not used in a first impl.: */
63
#define GLOBUS_GASS_CACHE_ERROR_LOCK_TIME_OUT -5
64
#define GLOBUS_GASS_CACHE_ERROR_OPEN_STATE -6
65
#define GLOBUS_GASS_CACHE_ERROR_STATE_F_CORRUPT -7
66
#define GLOBUS_GASS_CACHE_ERROR_NO_MEMORY -8
67
#define GLOBUS_GASS_CACHE_ERROR_CAN_NOT_CREATE_DATA_F -9
68
/* only for "done" or delete :*/
69
#define GLOBUS_GASS_CACHE_ERROR_URL_NOT_FOUND -10
70
#define GLOBUS_GASS_CACHE_ERROR_CAN_NOT_DEL_LOCK -11
71
#define GLOBUS_GASS_CACHE_ERROR_WRONG_TAG -12
72
#define GLOBUS_GASS_CACHE_ERROR_ALREADY_DONE -13
73
#define GLOBUS_GASS_CACHE_ERROR_CAN_NOT_WRITE -14
74
#define GLOBUS_GASS_CACHE_ERROR_CAN_NOT_READ -15
75
#define GLOBUS_GASS_CACHE_ERROR_CAN_NOT_DELETE_DATA_F -16
76
#define GLOBUS_GASS_CACHE_ERROR_CACHE_NOT_OPENED -17
77
#define GLOBUS_GASS_CACHE_ERROR_CACHE_ALREADY_OPENED -18
78
#define GLOBUS_GASS_CACHE_ERROR_INVALID_PARRAMETER -19
79
#define GLOBUS_GASS_CACHE_ERROR_INVALID_VERSION -20
80
#define GLOBUS_GASS_CACHE_ERROR_NO_SPACE -21
81
#define GLOBUS_GASS_CACHE_ERROR_QUOTA_EXCEEDED -22
83
#define GLOBUS_GASS_CACHE_TIMESTAMP_UNKNOWN 0UL
85
#if !defined(PATH_MAX) && defined(MAXPATHLEN)
86
# define PATH_MAX MAXPATHLEN
95
* Structure: globus_gass_cache_t
97
* Data structure used to store informations concerning an open cache
98
* directory. This structure MUST NOT be modified directly, but passed to
99
* the globus_gass_cache functions
101
typedef struct globus_i_gass_cache_t * globus_gass_cache_t;
111
* globus_gass_cache_open()
113
* Open the cache specified by the cache_directory_path argument, and return
114
* a cache handle that can be used in subsequent cache calls.
116
* If cache_directory_path is NULL, then use the value contained in the
117
* GLOBUS_GASS_CACHE_DEFAULT environment variable if it is defined,
118
* otherwise use ~/.globus_gass_cache.
120
* The cache_directory_path must be a directory. If it is a file, this call
121
* will fail with a non-0 return value.
123
* If the specified directory does not exist, then this call will create the
128
* cache_directory_path : Path to the cache directory to open.
129
* Can be NULL (see above)
131
* cache_handle->is_init: checked and return an error if
132
* cache_handle has already been used.
134
* cache_handle: Structure containning all the necessary
135
* information to access the cache (file names, descriptor,...)
136
* (see globus_gass_gache.h) Some files are also opened:
137
* globus_gass_cache_close() must be called subsequently to close those
139
* This parameter is modified by the globus_gass_cache_open()
142
* BLOBUS_SUCCESS or error code:
143
* GLOBUS_GASS_CACHE_ERROR_CACHE_ALREADY_OPENED
144
* GLOBUS_GASS_CACHE_ERROR_NAME_TOO_LONG if the cache directory path is
146
* GLOBUS_GASS_CACHE_ERROR_NO_HOME if cache_directory_path is NULL and
147
* the env. variable GLOBUS_GASS_CACHE_DEFAULT is empty and
148
* the env. variable $HOME is not defined !
149
* GLOBUS_GASS_CACHE_ERROR_CAN_NOT_CREATE if the cache directory or any
150
* necessary file can not be created.
155
globus_gass_cache_open(const char* cache_directory_path,
156
globus_gass_cache_t* cache_handle);
160
* globus_gass_cache_close()
163
* Close (NOT delete) a previously opened cache:
164
* - close the opened files and
165
* - free the memory allocated for the cache_handle.
166
* - mark the handle as "not initialized".
169
* cache_handle: Handler to the opened cahe directory to use.
171
* cache_handle->is_init set to "not initialized" and all the
172
* files opened bu globus_gass_cache_open are closed .
175
* GLOBUS_SUCCESS or error code:
176
* GLOBUS_GASS_CACHE_ERROR_CACHE_NOT_OPENED
180
globus_gass_cache_close(globus_gass_cache_t * cache_handle);
183
* globus_gass_cache_add()
185
* Create a new cache file or add a tag on it.
187
* If the URL is already in the cache but is locked, then this call will block
188
* until the cache entry is unlocked, then will proceed with the subsequent
191
* If the URL is already in the cache and unlocked, then add the tag to the
192
* cache entry's tag list, return the local cache filename in *local_filename,
193
* return the entry's current timestamp in *timestamp, lock the cache entry,
194
* and return GLOBUS_GASS_CACHE_ADD_EXISTS.
196
* If the URL is not in the cache, and create==GLOBUS_TRUE, then create a new
197
* unique empty local cache file, add it to the cache with the specified tag,
198
* return the filename in *local_filename, return *timestamp set to
199
* GLOBUS_GASS_TIMESTAMP_UNKNOWN, lock the cache entry, and
200
* return GLOBUS_GASS_CACHE_ADD_NEW.
202
* If the URL is not in the cache, and create==GLOBUS_FALSE, then do not
203
* add it to the cache, and return GLOBUS_GASS_CACHE_URL_NOT_FOUND.
205
* If this function returns GLOBUS_GASS_CACHE_ADD_EXISTS or
206
* GLOBUS_GASS_CACHE_ADD_NEW, then globus_gass_cache_add_done() or
207
* globus_gass_cache_delete() must be subsequently
208
* called to unlock the cache entry.
210
* Subsequent calls to globus_gass_cache_add() and
211
* globus_gass_cache_delete_start() on the same cache and url, made either
212
* from this process or another, will block until the cache entry is unlocked.
214
* If tag==NULL, then a tag with the value "null" will be added to the cache
217
* The same tag can be used multiple times, in which case this tag will be
218
* added to the entry's tag list multiple times.
220
* Note: It is recommended that proglobus_grams started via GLOBUS_GRAM
222
* of getenv("GLOBUS_GRAM_JOB_CONTACT"), since upon completion of a
223
* job GLOBUS_GRAM will automatically cleanup entries with this tag.
225
* Important Note: the local_filename MUST be free by the user in a
226
* subsequent operation, using globus_free()
230
* cache_handle - Handler to the opened cahe directory to use.
232
* url - url of the file to be cached. It is used as the main
233
* key to the cache entries.
235
* tag - tag specifying which job is/are using the cache. This
236
* is usually the GLOBUS_GRAM_JOB_CONTACT. Can be NULL or empty; the
237
* tag "null" is then used.
238
* create - Tells if the cache entry should be created if it is
239
* not already existing.
241
* timestamp - time stamp of the cached file, set by
242
* globus_gass_cache_done(), (or globus_gass_cache_delete() ).
244
* local_filename - Path the the local file caching the file
245
* specified by "url". NULL if "url" not yet cached and
246
* creation not requested (create false).
249
* GLOBUS_GASS_CACHE_URL_NOT_FOUND
250
* GLOBUS_GASS_CACHE_ADD_NEW
251
* GLOBUS_GASS_CACHE_ADD_EXISTS
252
* or any of the defined gass error code.
257
globus_gass_cache_add(globus_gass_cache_t cache_handle,
260
globus_bool_t create,
261
unsigned long *timestamp,
262
char **local_filename);
265
* globus_gass_cache_add_done()
267
* globus_gass_cache_add_done() MUST be called after globus_gass_cache_add(),
268
* to set the timestamp in the cache entry for the URL, and then unlock the
269
* cache entry. (The only case it does not need to be called is if
270
* globus_gass_cache_add() has returned GLOBUS_GASS_CACHE_URL_NOT_FOUND, of
274
* cache_handle - Handler to the opened cahe directory to use.
276
* url - url of the cached file to set as "done" (unlock)
277
* tag - tag specifying which job has locked the cache and must
278
* therfor be unlocked.It is an error to call this function
279
* with a tag which does not currently own the cache lock.
280
* timestamp: time stamp of the cached file.
284
* GLOBUS_SUCCESS or error code:
285
* or any of the defined gass error code.
288
globus_gass_cache_add_done(
289
globus_gass_cache_t cache_handle,
292
unsigned long timestamp);
295
* globus_gass_cache_query()
297
* Query if an item is in the cache
299
* This call will block only if wait_for_lock is GLOBUS_TRUE
303
* cache_handle - Handler to the opened cahe directory to use.
305
* url - url of the file to query. It is used as the main
306
* key to the cache entries.
308
* tag - tag specifying which job is/are using the cache. This
309
* is usually the GLOBUS_GRAM_JOB_CONTACT. Can be NULL or empty; the
310
* tag "null" is then used.
311
* create - Tells if the cache entry should be created if it is
312
* not already existing.
314
* wait_for_lock - If GLOBUS_TRUE, wait for any lock existing lock
315
* to be released. If GLOBUS_FALSE, doesn't wait for a lock to be
318
* timestamp - time stamp of the cached file, set by
319
* globus_gass_cache_done(), (or globus_gass_cache_delete() ).
321
* local_filename - Path the the local file caching the file
322
* specified by "url". NULL if "url" not yet cached and
323
* creation not requested (create false).
325
* is_locked - GLOBUS_TRUE if the file is currently (at return
330
* GLOBUS_GASS_CACHE_URL_NOT_FOUND
331
* or any of the defined gass error code.
335
globus_gass_cache_query(
336
globus_gass_cache_t cache_handle,
339
globus_bool_t wait_for_lock,
340
unsigned long *timestamp,
341
char **local_filename,
342
globus_bool_t *is_locked );
346
* globus_gass_cache_delete()
348
* Remove one instance of the tag from the cache entry's tag list.
350
* If there are no more tags in the tag list, then remove this cache
351
* entry and delete the associated local cache file.
353
* Otherwise, update the timestamp to the passed value.
355
* This call will leave the cache entry unlocked.
357
* If is_locked==GLOBUS_TRUE, then this cache entry was locked during a
358
* previous call to globus_gass_cache_add() or
359
* globus_gass_cache_delete_start(). The cache
360
* file should be locked by the corresponding url/tag, or an error is
361
* returned. If it is locked by the corresponding url/tag, then the normal
362
* operation occur, whithout blocking (remove one instance from the tag
363
* update the timestamp and unlock the cache).
365
* If is_locked==GLOBUS_FALSE, eventually wait the cache is not locked any
366
* more, and then proceed with the normal operations.(remove one instance
367
* from the tag list and update the timestamp).
370
* cache_handle - Handler to the opened cahe directory to use.
372
* url - url of the file to be cached. It is used as the main
373
* key to the cache entries.
375
* tag - tag specifying which job is/are using the cache. This
376
* is usually the GLOBUS_GRAM_JOB_CONTACT. Can be NULL or empty; the
377
* tag "null" is then used.
379
* timestamp - time stamp of the cached file.
381
* is_locked - indicate if this cache entry was locked during a
382
* previous call to globus_gass_cache_add() or
383
* globus_gass_cache_delete_start().
387
* GLOBUS_SUCCESS or error code:
388
* or any of the defined gass error code.
393
globus_gass_cache_delete_start(
394
globus_gass_cache_t cache_handle,
397
unsigned long *timestamp);
401
globus_gass_cache_delete(
402
globus_gass_cache_t cache_handle,
405
unsigned long timestamp,
406
globus_bool_t is_locked);
409
* globus_gass_cache_cleanup_tag()
411
* Remove all instances of the tag from the cache entry's tag list.
412
* If there are no more tags in the tag list, then remove this cache entry
413
* and delete the associated local cache file.
414
* If the cache entry is locked with the same tag as is passed to this
415
* function, then the entry is unlocked after removing the tags.
416
* Otherwise, the cache entry's lock is left untouched.
418
* This function does not block on a locked reference.
420
* Note: The GLOBUS_GRAM job manager will automatically call this function
421
* with a tag of getenv("GLOBUS_GRAM_JOB_CONTACT") upon completion of a job.
425
* cache_handle - Handler to the opened cahe directory to use.
427
* url - url of the file to be cached. It is used as the main
428
* key to the cache entries.
430
* tag - tag specifying which job is/are using the cache. This
431
* is usually the GLOBUS_GRAM_JOB_CONTACT. Can be NULL or empty; the
432
* tag "null" is then used.
436
* GLOBUS_SUCCESS or error code:
437
* or any of the defined gass error code.
441
globus_gass_cache_cleanup_tag(
442
globus_gass_cache_t cache_handle,
448
globus_gass_cache_cleanup_tag_all(
449
globus_gass_cache_t cache_handle,
453
* globus_l_gass_cache_mangle_url()
455
* Mangles the given URL into a chunk suitable for using as a file /
459
* cache_handle - Handler to the opened cahe directory to use.
461
* url - The incoming URL to mangle (\0 terminated)
463
* mangled_url - Pointer to the output string; a buffer for the
464
* real string is malloc()ed for the application. If mangled is
465
* NULL, then no such buffer is allocated, and no mangled string
466
* is created. This can be useful to just get the length of the
469
* Length - The length of the resulting string. If NULL, this is
474
* GLOBUS_GASS_CACHE_ERROR_NO_MEMORY
478
globus_gass_cache_mangle_url( const globus_gass_cache_t cache_handle,
484
* globus_l_gass_cache_mangle_tag()
486
* Mangles the given tag into a chunk suitable for using as a file /
490
* cache_handle - Handler to the opened cahe directory to use.
492
* tag - The incoming tag to mangle (\0 terminated)
494
* mangled_tag - Pointer to the output string; a buffer for the
495
* real string is malloc()ed for the application. If mangled is
496
* NULL, then no such buffer is allocated, and no mangled string
497
* is created. This can be useful to just get the length of the
500
* Length - The length of the resulting string. If NULL, this is
505
* GLOBUS_GASS_CACHE_ERROR_NO_MEMORY
509
globus_gass_cache_mangle_tag( const globus_gass_cache_t cache_handle,
515
* globus_gass_cache_get_dirs()
517
* Gets a bunch of directories. This is exported for use in the
518
* globus_gass_cache program.
521
* cache_handle - Handler to the opened cahe directory to use.
523
* URL - The incoming URL
525
* tag - The incoming tag
527
* local_root - Pointer to the "local root" directory
529
* global_root - Pointer to the "global root" directory
531
* tmp_root - Pointer to the "tmp root" directory
533
* log_root - Pointer to the root log directory
535
* local_dir - Pointer to the related "local" directory
537
* global_dir - Pointer to the related "global" directory
541
* GLOBUS_GASS_CACHE_ERROR_NO_MEMORY
545
globus_gass_cache_get_dirs( const globus_gass_cache_t cache_handle,
556
* globus_gass_cache_get_cache_dir()
558
* Gets a the root cache of directory. This is exported for use in the
559
* globus_gass_cache program.
562
* cache_handle - Handler to the opened cahe directory to use.
564
* cache_dir - Pointer to the cache directory
568
* GLOBUS_GASS_CACHE_ERROR_NO_MEMORY
572
globus_gass_cache_get_cache_dir( const globus_gass_cache_t cache_handle,
576
* globus_gass_cache_get_cache_type_string()
578
* Gets a string which describes the cache type ("normal" or "flat")
581
* cache_handle - Handler to the opened cahe directory to use.
583
* cache_type - Pointer to the strdup()ed string
587
* GLOBUS_GASS_CACHE_ERROR_NO_MEMORY
591
globus_gass_cache_get_cache_type_string( const globus_gass_cache_t cache_handle,
595
* globus_gass_cache_error_string()
597
* Return a pointer on an error description string.
600
* error_code: error code returned by a previously called
601
* globus_gass_cache function.
604
* Pointer to an error message, or NULL if invalide error code.
609
globus_gass_cache_error_string(
618
#define GLOBUS_GASS_CACHE_MODULE (&globus_i_gass_cache_module)
620
extern globus_module_descriptor_t globus_i_gass_cache_module;
623
#endif /* _GLOBUS_GASS_INCLUDE_GLOBUS_GASS_CACHE_H */