• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

P_CacheDisk.h

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022  */
00023 
00024 #ifndef _P_CACHE_DISK_H__
00025 #define _P_CACHE_DISK_H__
00026 
00027 #include "I_Cache.h"
00028 
00029 extern int cache_config_max_disk_errors;
00030 
00031 #define DISK_BAD(_x)                    ((_x)->num_errors >= cache_config_max_disk_errors)
00032 #define DISK_BAD_SIGNALLED(_x)          (_x->num_errors > cache_config_max_disk_errors)
00033 #define SET_DISK_BAD(_x)                (_x->num_errors = cache_config_max_disk_errors)
00034 #define SET_DISK_OKAY(_x)               (_x->num_errors = 0)
00035 
00036 #define VOL_BLOCK_SIZE                  (1024 * 1024 * 128)
00037 #define MIN_VOL_SIZE                    VOL_BLOCK_SIZE
00038 #define ROUND_DOWN_TO_VOL_BLOCK(_x)     (((_x) &~ (VOL_BLOCK_SIZE - 1)))
00039 #define VOL_BLOCK_SHIFT                 27
00040 #define ROUND_DOWN_TO_STORE_BLOCK(_x)   (((_x) >> STORE_BLOCK_SHIFT) << STORE_BLOCK_SHIFT)
00041 
00042 #define STORE_BLOCKS_PER_VOL            (VOL_BLOCK_SIZE / STORE_BLOCK_SIZE)
00043 #define DISK_HEADER_MAGIC               0xABCD1237
00044 
00045 /* each disk vol block has a corresponding Vol object */
00046 struct CacheDisk;
00047 
00048 struct DiskVolBlock
00049 {
00050   uint64_t offset;  // offset in bytes from the start of the disk
00051   uint64_t len;  // length in in store blocks
00052   int number;
00053   unsigned int type:3;
00054   unsigned int free:1;
00055 };
00056 
00057 struct DiskVolBlockQueue
00058 {
00059   DiskVolBlock *b;
00060   int new_block;                /* whether an existing vol or a new one */
00061   LINK(DiskVolBlockQueue, link);
00062 
00063   DiskVolBlockQueue()
00064     : b(NULL), new_block(0)
00065   { }
00066 };
00067 
00068 struct DiskVol
00069 {
00070   int num_volblocks;           /* number of disk volume blocks in this volume */
00071   int vol_number;              /* the volume number of this volume */
00072   uint64_t size;                  /* size in store blocks */
00073   CacheDisk *disk;
00074   Queue<DiskVolBlockQueue> dpb_queue;
00075 };
00076 
00077 struct DiskHeader
00078 {
00079   unsigned int magic;
00080   unsigned int num_volumes;            /* number of discrete volumes (DiskVol) */
00081   unsigned int num_free;               /* number of disk volume blocks free */
00082   unsigned int num_used;               /* number of disk volume blocks in use */
00083   unsigned int num_diskvol_blks;       /* number of disk volume blocks */
00084   uint64_t num_blocks;
00085   DiskVolBlock vol_info[1];
00086 };
00087 
00088 struct CacheDisk: public Continuation
00089 {
00090   DiskHeader *header;
00091   char *path;
00092   int header_len;
00093   AIOCallbackInternal io;
00094   off_t len;                // in blocks (STORE_BLOCK)
00095   off_t start;
00096   off_t skip;
00097   off_t num_usable_blocks;
00098   int hw_sector_size;
00099   int fd;
00100   off_t free_space;
00101   off_t wasted_space;
00102   DiskVol **disk_vols;
00103   DiskVol *free_blocks;
00104   int num_errors;
00105   int cleared;
00106 
00107   // Extra configuration values
00108   int forced_volume_num; ///< Volume number for this disk.
00109   ats_scoped_str hash_base_string; ///< Base string for hash seed.
00110  
00111   CacheDisk()
00112     : Continuation(new_ProxyMutex()), header(NULL),
00113       path(NULL), header_len(0), len(0), start(0), skip(0),
00114       num_usable_blocks(0), fd(-1), free_space(0), wasted_space(0),
00115       disk_vols(NULL), free_blocks(NULL), num_errors(0), cleared(0),
00116       forced_volume_num(-1)
00117   { }
00118 
00119    ~CacheDisk();
00120 
00121   int open(bool clear);
00122   int open(char *s, off_t blocks, off_t skip, int hw_sector_size, int fildes, bool clear);
00123   int clearDisk();
00124   int clearDone(int event, void *data);
00125   int openStart(int event, void *data);
00126   int openDone(int event, void *data);
00127   int sync();
00128   int syncDone(int event, void *data);
00129   DiskVolBlock *create_volume(int number, off_t size, int scheme);
00130   int delete_volume(int number);
00131   int delete_all_volumes();
00132   void update_header();
00133   DiskVol *get_diskvol(int vol_number);
00134 
00135 };
00136 
00137 
00138 #endif

Generated by  doxygen 1.7.1