1 /*
2  * Copyright (C) 2016 Jakub Kruszona-Zawadzki, Core Technology Sp. z o.o.
3  *
4  * This file is part of MooseFS.
5  *
6  * MooseFS is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, version 2 (only).
9  *
10  * MooseFS is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with MooseFS; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA
18  * or visit http://www.gnu.org/licenses/gpl-2.0.html
19  */
20 
21 #ifndef _HDDSPACEMGR_H_
22 #define _HDDSPACEMGR_H_
23 
24 #include <inttypes.h>
25 
26 #include "MFSCommunication.h"
27 
28 void hdd_stats(uint64_t *br,uint64_t *bw,uint32_t *opr,uint32_t *opw,uint32_t *dbr,uint32_t *dbw,uint32_t *dopr,uint32_t *dopw,uint64_t *rtime,uint64_t *wtime);
29 void hdd_op_stats(uint32_t *op_create,uint32_t *op_delete,uint32_t *op_version,uint32_t *op_duplicate,uint32_t *op_truncate,uint32_t *op_duptrunc,uint32_t *op_test);
30 uint32_t hdd_errorcounter(void);
31 
32 /* lock/unlock pair */
33 uint32_t hdd_get_damaged_chunk_count(void);
34 void hdd_get_damaged_chunk_data(uint8_t *buff);
35 /* lock/unlock pair */
36 uint32_t hdd_get_lost_chunk_count(uint32_t limit);
37 void hdd_get_lost_chunk_data(uint8_t *buff,uint32_t limit);
38 /* lock/unlock pair */
39 uint32_t hdd_get_new_chunk_count(uint32_t limit);
40 void hdd_get_new_chunk_data(uint8_t *buff,uint32_t limit);
41 /* lock/unlock pair */
42 uint32_t hdd_diskinfo_v1_size();
43 void hdd_diskinfo_v1_data(uint8_t *buff);
44 uint32_t hdd_diskinfo_v2_size();
45 void hdd_diskinfo_v2_data(uint8_t *buff);
46 /* lock/unlock pair */
47 void hdd_get_chunks_begin();
48 void hdd_get_chunks_end();
49 uint32_t hdd_get_chunks_next_list_count();
50 void hdd_get_chunks_next_list_data(uint8_t *buff);
51 //uint32_t hdd_get_chunks_count();
52 //void hdd_get_chunks_data(uint8_t *buff);
53 
54 //uint32_t get_changedchunkscount();
55 //void fill_changedchunksinfo(uint8_t *buff);
56 int hdd_spacechanged(void);
57 void hdd_get_space(uint64_t *usedspace,uint64_t *totalspace,uint32_t *chunkcount,uint64_t *tdusedspace,uint64_t *tdtotalspace,uint32_t *tdchunkcount);
58 
59 /* I/O operations */
60 int hdd_open(uint64_t chunkid,uint32_t version);
61 int hdd_close(uint64_t chunkid);
62 int hdd_read(uint64_t chunkid,uint32_t version,uint16_t blocknum,uint8_t *buffer,uint32_t offset,uint32_t size,uint8_t *crcbuff);
63 int hdd_write(uint64_t chunkid,uint32_t version,uint16_t blocknum,const uint8_t *buffer,uint32_t offset,uint32_t size,const uint8_t *crcbuff);
64 
65 /* chunk info */
66 // int hdd_check_version(uint64_t chunkid,uint32_t version);
67 int hdd_get_blocks(uint64_t chunkid,uint32_t version,uint8_t *blocks_buff);
68 int hdd_get_checksum(uint64_t chunkid, uint32_t version, uint8_t *checksum_buff);
69 int hdd_get_checksum_tab(uint64_t chunkid, uint32_t version, uint8_t *checksum_tab);
70 
71 /* chunk operations */
72 
73 /* all chunk operations in one call */
74 // newversion>0 && length==0xFFFFFFFF && copychunkid==0    -> change version
75 // newversion>0 && length==0xFFFFFFFF && copycnunkid>0     -> duplicate
76 // newversion>0 && length<=MFSCHUNKSIZE && copychunkid==0     -> truncate
77 // newversion>0 && length<=MFSCHUNKSIZE && copychunkid>0      -> duplicate and truncate
78 // newversion==0 && length==0                              -> delete
79 // newversion==0 && length==1                              -> create
80 // newversion==0 && length==2                              -> test
81 int hdd_chunkop(uint64_t chunkid,uint32_t version,uint32_t newversion,uint64_t copychunkid,uint32_t copyversion,uint32_t length);
82 
83 #define hdd_delete(_chunkid,_version) hdd_chunkop(_chunkid,_version,0,0,0,0)
84 #define hdd_create(_chunkid,_version) hdd_chunkop(_chunkid,_version,0,0,0,1)
85 #define hdd_test(_chunkid,_version) hdd_chunkop(_chunkid,_version,0,0,0,2)
86 #define hdd_version(_chunkid,_version,_newversion) (((_newversion)>0)?hdd_chunkop(_chunkid,_version,_newversion,0,0,0xFFFFFFFF):ERROR_EINVAL)
87 #define hdd_truncate(_chunkid,_version,_newversion,_length) (((_newversion)>0&&(_length)!=0xFFFFFFFF)?hdd_chunkop(_chunkid,_version,_newversion,0,0,_length):ERROR_EINVAL)
88 #define hdd_duplicate(_chunkid,_version,_newversion,_copychunkid,_copyversion) (((_newversion>0)&&(_copychunkid)>0)?hdd_chunkop(_chunkid,_version,_newversion,_copychunkid,_copyversion,0xFFFFFFFF):ERROR_EINVAL)
89 #define hdd_duptrunc(_chunkid,_version,_newversion,_copychunkid,_copyversion,_length) (((_newversion>0)&&(_copychunkid)>0&&(_length)!=0xFFFFFFFF)?hdd_chunkop(_chunkid,_version,_newversion,_copychunkid,_copyversion,_length):ERROR_EINVAL)
90 
91 /* initialization */
92 int hdd_late_init(void);
93 int hdd_init(void);
94 
95 /* debug only */
96 void hdd_test_show_chunks(void);
97 void hdd_test_show_openedchunks(void);
98 #endif
99