3
A brief file description
5
@section license License
7
Licensed to the Apache Software Foundation (ASF) under one
8
or more contributor license agreements. See the NOTICE file
9
distributed with this work for additional information
10
regarding copyright ownership. The ASF licenses this file
11
to you under the Apache License, Version 2.0 (the
12
"License"); you may not use this file except in compliance
13
with the License. You may obtain a copy of the License at
15
http://www.apache.org/licenses/LICENSE-2.0
17
Unless required by applicable law or agreed to in writing, software
18
distributed under the License is distributed on an "AS IS" BASIS,
19
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
See the License for the specific language governing permissions and
21
limitations under the License.
24
/****************************************************************************
29
****************************************************************************/
36
#define STORE_BLOCK_SIZE 8192
37
#define STORE_BLOCK_SHIFT 13
38
#define DEFAULT_HW_SECTOR_SIZE 512
41
// A Store is a place to store data.
42
// Those on the same disk should be in a linked list.
48
int64_t hw_sector_size;
49
bool file_pathname; // the pathname is a file
51
int64_t offset; // used only if (file == true)
57
bool is_mmapable_internal;
59
bool is_mmapable() { return is_mmapable_internal; }
60
void set_mmapable(bool s) { is_mmapable_internal = s; }
61
int64_t size() { return blocks * STORE_BLOCK_SIZE; }
63
int64_t total_blocks() {
65
return blocks + link.next->total_blocks();
80
for (Span * x = this; x; i++, x = x->link.next);
87
int64_t end() { return offset + blocks; }
89
const char *init(char *n, int64_t size);
91
// 0 on success -1 on failure
92
int path(char *filename, // for non-file, the filename in the director
93
int64_t * offset, // for file, start offset (unsupported)
94
char *buf, int buflen); // where to store the path
96
Span():pathname(NULL), blocks(0), hw_sector_size(DEFAULT_HW_SECTOR_SIZE), file_pathname(false),
97
isRaw(true), offset(0), alignment(0), disk_id(0), is_mmapable_internal(false) {
106
// Thread-safe operations
109
// spread evenly on all disks
110
void spread_alloc(Store & s, unsigned int blocks, bool mmapable = true);
111
void alloc(Store & s, unsigned int blocks, bool only_one = false, bool mmapable = true);
113
Span *alloc_one(unsigned int blocks, bool mmapable) {
115
alloc(s, blocks, true, mmapable);
124
// try to allocate, return (s == gotten, diff == not gotten)
125
void try_realloc(Store & s, Store & diff);
127
// free back the contents of a store.
128
// must have been JUST allocated (no intervening allocs/frees)
129
void free(Store & s);
137
disk = (Span **) xrealloc(disk, i * sizeof(Span *));
138
for (int j = n_disks; j < i; j++)
144
// Non Thread-safe operations
145
unsigned int total_blocks(int after = 0) {
147
for (int i = after; i < n_disks; i++)
149
t += disk[i]->total_blocks();
150
return (unsigned int) t;
152
// 0 on success -1 on failure
153
// these operations are NOT thread-safe
155
int write(int fd, char *name);
156
int read(int fd, char *name);
157
int clear(char *filename, bool clear_dirs = true);
160
int remove(char *pathname);
168
// returns NULL on success
169
// if fd >= 0 then on failure it returns an error string
170
// otherwise on failure it returns (char *)-1
172
const char *read_config(int fd = -1);
173
int write_config_data(int fd);
176
extern Store theStore;
178
// store either free or in the cache, can be stolen for reconfiguration
179
void stealStore(Store & s, int blocks);
180
int initialize_store();
182
struct storageConfigFile {
183
const char *parseFile(int fd) {
185
return tStore.read_config(fd);