Skip to content

Commit be4f3c4

Browse files
madjescMauricio
authored andcommitted
chore: apply format
a xd
1 parent 4fb452d commit be4f3c4

File tree

133 files changed

+17939
-19360
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+17939
-19360
lines changed

.clang-format

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# - C++-style comments (//) restricted to logic comment-out only
1313
# - Magic editor lines (vim/emacs modelines)
1414
---
15-
Language: C
1615
ColumnLimit: 120
1716
IndentWidth: 2
1817
UseTab: Always

src/iosched/cache_manager.c

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
**
4747
*************************************************************************************
4848
*/
49-
#include "libltfs/ltfs.h"
5049
#include "cache_manager.h"
50+
#include "libltfs/ltfs.h"
5151

5252
/**
5353
* cache_pool structure.
@@ -62,23 +62,25 @@
6262
* have been allocated through this cache pool; it doesn't necessarily say how
6363
* many available objects are in the pool.
6464
*/
65-
struct cache_pool {
66-
size_t object_size; /**< The size of each object in this pool */
67-
size_t initial_capacity; /**< Low water mark. Defines the initial capacity of the pool */
68-
size_t max_capacity; /**< High water mark. Defines the maximum capacity of the pool */
69-
size_t current_capacity; /**< How many objects are currently allocated */
65+
struct cache_pool
66+
{
67+
size_t object_size; /**< The size of each object in this pool */
68+
size_t initial_capacity; /**< Low water mark. Defines the initial capacity of the pool */
69+
size_t max_capacity; /**< High water mark. Defines the maximum capacity of the pool */
70+
size_t current_capacity; /**< How many objects are currently allocated */
7071
TAILQ_HEAD(objects_struct, cache_object) pool; /**< Pool of cached objects */
7172
};
7273

7374
/**
7475
* cache_object structure.
7576
* Holds objects of size @object_size, as stored in the cache_pool structure.
7677
*/
77-
struct cache_object {
78-
uint32_t refcount; /**< Reference count */
79-
ltfs_mutex_t lock; /**< Lock to protect access to the refcount */
80-
void *data; /**< Cached data. Must be the first element in the structure */
81-
struct cache_pool *pool; /**< Backpointer to the cache pool this object is part of */
78+
struct cache_object
79+
{
80+
uint32_t refcount; /**< Reference count */
81+
ltfs_mutex_t lock; /**< Lock to protect access to the refcount */
82+
void *data; /**< Cached data. Must be the first element in the structure */
83+
struct cache_pool *pool; /**< Backpointer to the cache pool this object is part of */
8284
TAILQ_ENTRY(cache_object) list; /**< Pointers to next and previous cache objects */
8385
};
8486

@@ -92,12 +94,13 @@ struct cache_object *_cache_manager_create_object(struct cache_pool *pool)
9294
{
9395
int ret;
9496
struct cache_object *object = calloc(1, sizeof(struct cache_object));
95-
if (! object) {
97+
if (!object) {
9698
ltfsmsg(LTFS_ERR, 10001E, "cache manager: object");
9799
return NULL;
98100
}
99-
object->data = calloc(1, pool->object_size + LTFS_CRC_SIZE); /* Allocate extra 4-bytes for SCSI logical block protection */
100-
if (! object->data) {
101+
object->data =
102+
calloc(1, pool->object_size + LTFS_CRC_SIZE); /* Allocate extra 4-bytes for SCSI logical block protection */
103+
if (!object->data) {
101104
ltfsmsg(LTFS_ERR, 10001E, "cache manager: object data");
102105
free(object);
103106
return NULL;
@@ -127,8 +130,8 @@ void *cache_manager_init(size_t object_size, size_t initial_capacity, size_t max
127130
struct cache_pool *pool;
128131
size_t i;
129132

130-
pool = (struct cache_pool *) calloc(1, sizeof (struct cache_pool));
131-
if (! pool) {
133+
pool = (struct cache_pool *)calloc(1, sizeof(struct cache_pool));
134+
if (!pool) {
132135
ltfsmsg(LTFS_ERR, 10001E, "cache manager: pool");
133136
return NULL;
134137
}
@@ -138,16 +141,16 @@ void *cache_manager_init(size_t object_size, size_t initial_capacity, size_t max
138141
pool->current_capacity = initial_capacity;
139142
TAILQ_INIT(&pool->pool);
140143

141-
for (i=0; i<initial_capacity; ++i) {
144+
for (i = 0; i < initial_capacity; ++i) {
142145
struct cache_object *object = _cache_manager_create_object(pool);
143-
if (! object) {
146+
if (!object) {
144147
ltfsmsg(LTFS_ERR, 11114E);
145148
cache_manager_destroy(pool);
146149
return NULL;
147150
}
148151
}
149152

150-
return (void *) pool;
153+
return (void *)pool;
151154
}
152155

153156
/**
@@ -157,17 +160,17 @@ void *cache_manager_init(size_t object_size, size_t initial_capacity, size_t max
157160
void cache_manager_destroy(void *cache)
158161
{
159162
struct cache_object *object, *aux;
160-
struct cache_pool *pool = (struct cache_pool *) cache;
161-
if (! pool) {
163+
struct cache_pool *pool = (struct cache_pool *)cache;
164+
if (!pool) {
162165
ltfsmsg(LTFS_WARN, 10006W, "pool", __FUNCTION__);
163166
return;
164167
}
165168

166-
TAILQ_FOREACH_SAFE(object, &pool->pool, list, aux) {
169+
TAILQ_FOREACH_SAFE(object, &pool->pool, list, aux)
170+
{
167171
TAILQ_REMOVE(&pool->pool, object, list);
168172
ltfs_mutex_destroy(&object->lock);
169-
if (object->data)
170-
free(object->data);
173+
if (object->data) free(object->data);
171174
free(object);
172175
}
173176

@@ -181,10 +184,10 @@ void cache_manager_destroy(void *cache)
181184
*/
182185
bool cache_manager_has_room(void *cache)
183186
{
184-
struct cache_pool *pool = (struct cache_pool *) cache;
187+
struct cache_pool *pool = (struct cache_pool *)cache;
185188
CHECK_ARG_NULL(pool, false);
186189

187-
return ! (TAILQ_EMPTY(&pool->pool) && pool->current_capacity == pool->max_capacity);
190+
return !(TAILQ_EMPTY(&pool->pool) && pool->current_capacity == pool->max_capacity);
188191
}
189192

190193
/**
@@ -202,14 +205,15 @@ void *cache_manager_allocate_object(void *cache)
202205
{
203206
size_t i, new_size = 0;
204207
struct cache_object *object, *last_object = NULL;
205-
struct cache_pool *pool = (struct cache_pool *) cache;
208+
struct cache_pool *pool = (struct cache_pool *)cache;
206209
CHECK_ARG_NULL(pool, NULL);
207210

208-
TAILQ_FOREACH(object, &pool->pool, list) {
211+
TAILQ_FOREACH(object, &pool->pool, list)
212+
{
209213
/* Return the first available object */
210214
TAILQ_REMOVE(&pool->pool, object, list);
211215
object->refcount = 1;
212-
return (void *) object;
216+
return (void *)object;
213217
}
214218

215219
/*
@@ -229,9 +233,9 @@ void *cache_manager_allocate_object(void *cache)
229233
/* Expand until the maximum capacity */
230234
new_size = pool->max_capacity;
231235

232-
for (i=pool->current_capacity; i<new_size; ++i) {
236+
for (i = pool->current_capacity; i < new_size; ++i) {
233237
struct cache_object *object = _cache_manager_create_object(pool);
234-
if (! object) {
238+
if (!object) {
235239
/* Luckily we might have increased the size of the cache by a few entries.. */
236240
ltfsmsg(LTFS_WARN, 11115W);
237241
break;
@@ -240,7 +244,7 @@ void *cache_manager_allocate_object(void *cache)
240244
pool->current_capacity++;
241245
}
242246

243-
if (! last_object) {
247+
if (!last_object) {
244248
/* If we couldn't grow the cache any further return failure */
245249
ltfsmsg(LTFS_ERR, 11116E);
246250
return NULL;
@@ -258,7 +262,7 @@ void *cache_manager_allocate_object(void *cache)
258262
*/
259263
void *cache_manager_get_object(void *cache_object)
260264
{
261-
struct cache_object *object = (struct cache_object *) cache_object;
265+
struct cache_object *object = (struct cache_object *)cache_object;
262266

263267
CHECK_ARG_NULL(cache_object, NULL);
264268

@@ -276,8 +280,8 @@ void *cache_manager_get_object(void *cache_object)
276280
void cache_manager_free_object(void *cache_object, size_t count)
277281
{
278282
struct cache_pool *pool;
279-
struct cache_object *object = (struct cache_object *) cache_object;
280-
if (! object) {
283+
struct cache_object *object = (struct cache_object *)cache_object;
284+
if (!object) {
281285
ltfsmsg(LTFS_WARN, 10006W, "object", __FUNCTION__);
282286
return;
283287
}
@@ -316,7 +320,7 @@ void cache_manager_free_object(void *cache_object, size_t count)
316320
*/
317321
void *cache_manager_get_object_data(void *cache_object)
318322
{
319-
struct cache_object *object = (struct cache_object *) cache_object;
323+
struct cache_object *object = (struct cache_object *)cache_object;
320324
CHECK_ARG_NULL(object, NULL);
321325
return object->data;
322326
}
@@ -328,7 +332,7 @@ void *cache_manager_get_object_data(void *cache_object)
328332
*/
329333
size_t cache_manager_get_object_size(void *cache_object)
330334
{
331-
struct cache_object *object = (struct cache_object *) cache_object;
335+
struct cache_object *object = (struct cache_object *)cache_object;
332336
CHECK_ARG_NULL(object, 0);
333337
return object->pool->object_size;
334338
}

src/iosched/cache_manager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
*/
4949
#ifndef __cache_manager_h
5050
#define __cache_manager_h
51+
#include <stdbool.h>
52+
#include <stdlib.h>
5153

5254
void *cache_manager_init(size_t object_size, size_t initial_capacity, size_t max_capacity);
5355
void cache_manager_destroy(void *cache);

src/iosched/fcfs.c

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,18 @@
4747
*************************************************************************************
4848
*/
4949

50+
#include "libltfs/iosched_ops.h"
5051
#include "libltfs/ltfs.h"
5152
#include "libltfs/ltfs_fsops_raw.h"
5253
#include "ltfs_copyright.h"
53-
#include "libltfs/iosched_ops.h"
5454

55-
volatile char *copyright = LTFS_COPYRIGHT_0"\n"LTFS_COPYRIGHT_1"\n"LTFS_COPYRIGHT_2"\n" \
56-
LTFS_COPYRIGHT_3"\n"LTFS_COPYRIGHT_4"\n"LTFS_COPYRIGHT_5"\n";
55+
volatile char *copyright = LTFS_COPYRIGHT_0 "\n" LTFS_COPYRIGHT_1 "\n" LTFS_COPYRIGHT_2 "\n" LTFS_COPYRIGHT_3
56+
"\n" LTFS_COPYRIGHT_4 "\n" LTFS_COPYRIGHT_5 "\n";
5757

58-
struct fcfs_data {
59-
ltfs_mutex_t sched_lock; /**< Serializes read and write access */
60-
struct ltfs_volume *vol; /**< A reference to the LTFS volume structure */
58+
struct fcfs_data
59+
{
60+
ltfs_mutex_t sched_lock; /**< Serializes read and write access */
61+
struct ltfs_volume *vol; /**< A reference to the LTFS volume structure */
6162
};
6263

6364
/**
@@ -69,7 +70,7 @@ void *fcfs_init(struct ltfs_volume *vol)
6970
{
7071
int ret;
7172
struct fcfs_data *priv = calloc(1, sizeof(struct fcfs_data));
72-
if (! priv) {
73+
if (!priv) {
7374
ltfsmsg(LTFS_ERR, 10001E, __FUNCTION__);
7475
return NULL;
7576
}
@@ -91,7 +92,7 @@ void *fcfs_init(struct ltfs_volume *vol)
9192
*/
9293
int fcfs_destroy(void *iosched_handle)
9394
{
94-
struct fcfs_data *priv = (struct fcfs_data *) iosched_handle;
95+
struct fcfs_data *priv = (struct fcfs_data *)iosched_handle;
9596
CHECK_ARG_NULL(iosched_handle, -LTFS_NULL_ARG);
9697

9798
ltfs_mutex_destroy(&priv->sched_lock);
@@ -110,7 +111,7 @@ int fcfs_destroy(void *iosched_handle)
110111
*/
111112
int fcfs_open(const char *path, bool open_write, struct dentry **dentry, void *iosched_handle)
112113
{
113-
struct fcfs_data *priv = (struct fcfs_data *) iosched_handle;
114+
struct fcfs_data *priv = (struct fcfs_data *)iosched_handle;
114115

115116
CHECK_ARG_NULL(path, -LTFS_NULL_ARG);
116117
CHECK_ARG_NULL(dentry, -LTFS_NULL_ARG);
@@ -147,7 +148,7 @@ int fcfs_close(struct dentry *d, bool flush, void *iosched_handle)
147148
*/
148149
ssize_t fcfs_read(struct dentry *d, char *buf, size_t size, off_t offset, void *iosched_handle)
149150
{
150-
struct fcfs_data *priv = (struct fcfs_data *) iosched_handle;
151+
struct fcfs_data *priv = (struct fcfs_data *)iosched_handle;
151152

152153
CHECK_ARG_NULL(d, -LTFS_NULL_ARG);
153154
CHECK_ARG_NULL(buf, -LTFS_NULL_ARG);
@@ -167,10 +168,10 @@ ssize_t fcfs_read(struct dentry *d, char *buf, size_t size, off_t offset, void *
167168
* @param iosched_handle the I/O scheduler handle
168169
* @return the number of bytes enqueued for writing or a negative value on error
169170
*/
170-
ssize_t fcfs_write(struct dentry *d, const char *buf, size_t size, off_t offset,
171-
bool isupdatetime, void *iosched_handle)
171+
ssize_t
172+
fcfs_write(struct dentry *d, const char *buf, size_t size, off_t offset, bool isupdatetime, void *iosched_handle)
172173
{
173-
struct fcfs_data *priv = (struct fcfs_data *) iosched_handle;
174+
struct fcfs_data *priv = (struct fcfs_data *)iosched_handle;
174175

175176
CHECK_ARG_NULL(d, -LTFS_NULL_ARG);
176177
CHECK_ARG_NULL(buf, -LTFS_NULL_ARG);
@@ -189,7 +190,7 @@ ssize_t fcfs_write(struct dentry *d, const char *buf, size_t size, off_t offset,
189190
*/
190191
int fcfs_flush(struct dentry *d, bool closeflag, void *iosched_handle)
191192
{
192-
(void) closeflag;
193+
(void)closeflag;
193194

194195
CHECK_ARG_NULL(d, -LTFS_NULL_ARG);
195196
CHECK_ARG_NULL(iosched_handle, -LTFS_NULL_ARG);
@@ -199,7 +200,7 @@ int fcfs_flush(struct dentry *d, bool closeflag, void *iosched_handle)
199200

200201
int fcfs_truncate(struct dentry *d, off_t length, void *iosched_handle)
201202
{
202-
struct fcfs_data *priv = (struct fcfs_data *) iosched_handle;
203+
struct fcfs_data *priv = (struct fcfs_data *)iosched_handle;
203204

204205
CHECK_ARG_NULL(d, -LTFS_NULL_ARG);
205206
CHECK_ARG_NULL(iosched_handle, -LTFS_NULL_ARG);
@@ -251,14 +252,14 @@ int fcfs_set_profiler(char *work_dir, bool enable, void *iosched_handle)
251252
}
252253

253254
struct iosched_ops fcfs_ops = {
254-
.init = fcfs_init,
255-
.destroy = fcfs_destroy,
256-
.open = fcfs_open,
257-
.close = fcfs_close,
258-
.read = fcfs_read,
259-
.write = fcfs_write,
260-
.flush = fcfs_flush,
261-
.truncate = fcfs_truncate,
255+
.init = fcfs_init,
256+
.destroy = fcfs_destroy,
257+
.open = fcfs_open,
258+
.close = fcfs_close,
259+
.read = fcfs_read,
260+
.write = fcfs_write,
261+
.flush = fcfs_flush,
262+
.truncate = fcfs_truncate,
262263
.get_filesize = fcfs_get_filesize,
263264
.update_data_placement = fcfs_update_data_placement,
264265
.set_profiler = fcfs_set_profiler,

0 commit comments

Comments
 (0)