scfs.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. /*
  2. * fs/scfs/scfs.h
  3. *
  4. * Copyright (C) 2014 Samsung Electronics Co., Ltd.
  5. * Authors: Sunghwan Yun <sunghwan.yun@samsung.com>
  6. * Jongmin Kim <jm45.kim@samsung.com>
  7. * Sangwoo Lee <sangwoo2.lee@samsung.com>
  8. * Inbae Lee <inbae.lee@samsung.com>
  9. *
  10. * This program has been developed as a stackable file system based on
  11. * the WrapFS, which was written by:
  12. *
  13. * Copyright (C) 1997-2003 Erez Zadok
  14. * Copyright (C) 2001-2003 Stony Brook University
  15. * Copyright (C) 2004-2006 International Business Machines Corp.
  16. * Author(s): Michael A. Halcrow <mahalcro@us.ibm.com>
  17. * Michael C. Thompson <mcthomps@us.ibm.com>
  18. *
  19. * This program is free software: you can redistribute it and/or modify
  20. * it under the terms of the GNU General Public License as published by
  21. * the Free Software Foundation, either version 2 of the License, or
  22. * (at your option) any later version.
  23. *
  24. * This program is distributed in the hope that it will be useful, but
  25. * WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  27. * General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU General Public License
  30. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  31. */
  32. #ifndef SCFS_HEADER_H
  33. #define SCFS_HEADER_H
  34. #include <linux/file.h>
  35. #include <linux/fs_stack.h>
  36. #include <linux/mount.h>
  37. #include <linux/namei.h>
  38. #include <linux/pagemap.h>
  39. #include <linux/page-flags.h>
  40. #include <linux/slab.h>
  41. #include <linux/buffer_head.h>
  42. #include <linux/backing-dev.h>
  43. #include <linux/vmalloc.h>
  44. #include <linux/time.h>
  45. #include <linux/mempool.h>
  46. #include <linux/version.h>
  47. #include <linux/debugfs.h>
  48. #include <linux/syscalls.h>
  49. #include <linux/delay.h>
  50. #include <linux/kernel.h>
  51. #include <linux/path.h>
  52. extern const struct address_space_operations scfs_aops;
  53. extern const struct inode_operations scfs_symlink_iops;
  54. extern const struct inode_operations scfs_dir_iops;
  55. extern const struct inode_operations scfs_file_iops;
  56. extern const struct file_operations scfs_dir_fops;
  57. extern const struct file_operations scfs_file_fops;
  58. extern const struct super_operations scfs_sops;
  59. extern const struct dentry_operations scfs_dops;
  60. extern struct kmem_cache *scfs_file_info_cache;
  61. extern struct kmem_cache *scfs_dentry_info_cache;
  62. extern struct kmem_cache *scfs_inode_info_cache;
  63. extern struct kmem_cache *scfs_sb_info_cache;
  64. /*****************/
  65. /* debug options */
  66. /*****************/
  67. //#define SCFS_DEBUG
  68. //#define SCFS_PROFILE
  69. //#define SCFS_PROFILE_MEM
  70. /*****************************************/
  71. /* size configs, flags, error code, etc. */
  72. /*****************************************/
  73. /* magic values for sanity checking */
  74. #define SCFS_SUPER_MAGIC 0x53305955
  75. #define SCFS_MAGIC SCFS_SUPER_MAGIC
  76. /* cluster size */
  77. #define SCFS_CLUSTER_ALIGN_BYTE 4
  78. #define SCFS_CLUSTER_SIZE_DEF (16 * 1024)
  79. #define SCFS_CLUSTER_SIZE_MAX (16 * 1024)
  80. #define SCFS_CLUSTER_SIZE_MIN (4 * 1024)
  81. /* mount option & file status flags */
  82. #define SCFS_DATA_RAW 0x00000001
  83. #define SCFS_DATA_COMPRESSABLE 0x00000002
  84. #define SCFS_META_XATTR 0x00000004
  85. #define SCFS_CINFO_OVER_PAGESIZE 0x00000008
  86. /* scfs meta status */
  87. #define SCFS_INVALID_META 0x00000010
  88. #define SCFS_MISSING_META 0x00000020
  89. #define SCFS_WRITE_OPENED 0x00000080
  90. /* mempool for cluster buffers */
  91. /* i.e. flagship (16KB clusters): 32KB x 32, low-end (8KB): 16KB x 32 */
  92. #define SCFS_MEMPOOL_COUNT 32
  93. #define SCFS_MEMPOOL_ORDER 2
  94. #define SCFS_MEMPOOL_SIZE (1 << SCFS_MEMPOOL_ORDER << PAGE_SHIFT)
  95. #define SCFS_MEMPOOL_SIZE_TOTAL (SCFS_MEMPOOL_COUNT * SCFS_MEMPOOL_SIZE)
  96. /* misc */
  97. #define SCFS_IO_MAX_RETRY 10
  98. #define IS_POW2(n) (n != 0 && ((n & (n - 1)) == 0))
  99. #define EMPTY_FLAG -1
  100. /* read performance tuning stuff */
  101. #define MAX_BUFFER_CACHE (SCFS_MEMPOOL_COUNT / 2)
  102. #define SCFS_ASYNC_READ_PAGES
  103. #define SCFS_READ_PAGES_PROFILE
  104. #if (defined(SCFS_READ_PAGES_PROFILE) && defined(SCFS_ASYNC_READ_PAGES))
  105. #define SCFS_ASYNC_READ_PROFILE
  106. #endif
  107. #ifdef SCFS_ASYNC_READ_PAGES
  108. //#define SCFS_SMB_THREAD_CPU_AFFINITY
  109. #define MAX_PAGE_BUFFER_SIZE_SMB 2048
  110. /* read helper thread wakeup threshold : 2 ~ 4 smb_thread each in order */
  111. #define SMB_THREAD_THRESHOLD_2 MAX_PAGE_BUFFER_SIZE_SMB / 64 // 32 pages
  112. #define SMB_THREAD_THRESHOLD_3 MAX_PAGE_BUFFER_SIZE_SMB / 32 // 64 pages
  113. #define SMB_THREAD_THRESHOLD_4 MAX_PAGE_BUFFER_SIZE_SMB / 16 // 128 pages
  114. #endif
  115. //#define SCFS_NOTIFY_RANDOM_READ
  116. //#define SCFS_REMOVE_NO_COMPRESSED_UPPER_MEMCPY
  117. /* This flag is the switch to go to ver. 1.3 */
  118. //#define SCFS_MULTI_THREAD_COMPRESSION
  119. /* using crypto module and multi-thread-compression are exclusive */
  120. #ifdef CONFIG_SCFS_USE_CRYPTO
  121. #undef SCFS_MULTI_THREAD_COMPRESSION
  122. #endif
  123. #ifdef SCFS_MULTI_THREAD_COMPRESSION
  124. #define SMTC_THREAD_THRESHOLD_2 4 // # of clusters
  125. #define SMTC_THREAD_THRESHOLD_3 8 // # of clusters
  126. #define SMTC_THREAD_THRESHOLD_4 16 // # of clusters
  127. #define SMTC_PENDING_THRESHOLD 8000
  128. #endif
  129. /*******************************/
  130. /* compression & cluster stuff */
  131. /*******************************/
  132. struct scfs_compressor {
  133. int compr_type;
  134. const char *name;
  135. struct crypto_comp *cc;
  136. struct mutex *comp_mutex;
  137. struct mutex *decomp_mutex;
  138. const char *capi_name;
  139. };
  140. enum comp_type {
  141. SCFS_COMP_NONE = 0,
  142. SCFS_COMP_LZO,
  143. SCFS_COMP_ZLIB,
  144. SCFS_COMP_BZIP2,
  145. SCFS_COMP_FASTLZO,
  146. SCFS_COMP_TOTAL_TYPES,
  147. };
  148. struct scfs_cinfo
  149. {
  150. __u32 offset; // byte offset of the start of this cluster
  151. __u32 size; // byte length of the cluster
  152. };
  153. /*****************************************************************/
  154. /* footer = scfs_cinfo * n_cluster + comp_footer (@ end of file) */
  155. /*****************************************************************/
  156. struct comp_footer
  157. {
  158. __s32 footer_size;
  159. __s32 cluster_size;
  160. __s64 original_file_size;
  161. __s32 comp_type;
  162. __s32 magic;
  163. };
  164. /***************************************/
  165. /* fs-wide structs (mount, inode, etc. */
  166. /***************************************/
  167. enum scfs_mode {
  168. SM_LowInval, /* Lower page cache invalidation */
  169. __NR_SCFSMODE,
  170. };
  171. struct read_buffer_cache {
  172. struct page *u_page;
  173. struct page *c_page;
  174. int ino;
  175. int clust_num;
  176. int is_compressed;
  177. atomic_t is_used;
  178. };
  179. struct scfs_mount_options
  180. {
  181. int flags;
  182. int cluster_size;
  183. int comp_threshold;
  184. enum comp_type comp_type;
  185. };
  186. struct scfs_sb_info
  187. {
  188. struct super_block *lower_sb;
  189. struct scfs_mount_options options;
  190. struct backing_dev_info bdi;
  191. mempool_t *mempool;
  192. /* for free (lower) space check */
  193. atomic_t current_file_count; /* opened files */
  194. atomic_t total_cluster_count; /* total clusters to be written to lower */
  195. atomic64_t current_data_size; /* total data size in memory */
  196. #if MAX_BUFFER_CACHE
  197. struct read_buffer_cache buffer_cache[MAX_BUFFER_CACHE];
  198. spinlock_t buffer_cache_lock;
  199. int read_buffer_index;
  200. #endif
  201. #ifndef CONFIG_SCFS_USE_CRYPTO
  202. void *scfs_workdata;
  203. spinlock_t workdata_lock;
  204. #endif
  205. #ifdef CONFIG_DEBUG_FS
  206. struct dentry *scfs_debugfs_root;
  207. #endif
  208. #ifdef SCFS_ASYNC_READ_PAGES
  209. atomic_t scfs_standby_readpage_count;
  210. u64 scfs_readpage_total_count;
  211. u64 scfs_readpage_io_count;
  212. u64 scfs_lowerpage_total_count;
  213. u64 scfs_lowerpage_reclaim_count;
  214. u64 scfs_lowerpage_alloc_count;
  215. u64 scfs_op_mode;
  216. u64 scfs_sequential_page_number;
  217. u64 buffer_cache_overflow_count_smb;
  218. u64 buffer_cache_reclaimed_before_used_count;
  219. /* when page_buffer_smb and file_buffer_smb is full, then this filling_index is
  220. set to MAX_PAGE_BUFFER_SIZE */
  221. u32 page_buffer_next_filling_index_smb;
  222. u32 page_buffer_next_io_index_smb;
  223. u32 max_page_buffer_size_smb;
  224. spinlock_t spinlock_smb;
  225. /* helper threads to process multiple read I/Os simultaneously */
  226. struct task_struct *smb_task[NR_CPUS];
  227. int smb_task_status[NR_CPUS];
  228. /* memory and file buffer for scfs_readpages, for queueing read requests */
  229. struct page *page_buffer_smb[MAX_PAGE_BUFFER_SIZE_SMB];
  230. struct file *file_buffer_smb[MAX_PAGE_BUFFER_SIZE_SMB];
  231. #endif
  232. #ifdef SCFS_MULTI_THREAD_COMPRESSION
  233. struct list_head sii_list;
  234. spinlock_t sii_list_lock;
  235. int cbm_list_total_count;
  236. /* helper threads to process multiple write I/Os simultaneously */
  237. struct task_struct *smtc_task[NR_CPUS];
  238. struct kmem_cache *scfs_cbm_cache;
  239. void *smtc_workdata[NR_CPUS];
  240. atomic_t smtc_idx;
  241. /* helper threads to write compressed cluster buffer */
  242. struct task_struct *smtc_writer_task;
  243. int smtc_writer_task_status;
  244. #endif
  245. #ifdef SCFS_PROFILE_MEM
  246. atomic_t mempooled_size;
  247. atomic_t kmalloced_size;
  248. atomic_t vmalloced_size;
  249. atomic_t kmcached_size;
  250. #endif
  251. };
  252. struct cinfo_entry
  253. {
  254. struct list_head entry;
  255. struct scfs_cinfo cinfo;
  256. unsigned int current_cluster_idx;
  257. int pad;
  258. };
  259. struct scfs_cluster_buffer
  260. {
  261. struct page *u_page;
  262. struct page *c_page;
  263. char *u_buffer;
  264. char *c_buffer;
  265. size_t original_size;
  266. };
  267. #ifdef SCFS_MULTI_THREAD_COMPRESSION
  268. struct scfs_cluster_buffer_mtc
  269. {
  270. struct scfs_cluster_buffer entry;
  271. struct cinfo_entry *info_entry;
  272. struct list_head list;
  273. int is_compress_write_done;
  274. };
  275. #endif
  276. struct scfs_inode_info
  277. {
  278. int flags;
  279. struct mutex lower_file_mutex;
  280. struct mutex cinfo_mutex;
  281. atomic_t lower_file_count;
  282. struct inode *lower_inode;
  283. void *cinfo_array;
  284. int cinfo_array_size;
  285. int cluster_size;
  286. enum comp_type comp_type;
  287. size_t upper_file_size;
  288. struct scfs_cluster_buffer cluster_buffer;
  289. struct list_head cinfo_list;
  290. unsigned char compressed;
  291. #ifdef SCFS_MULTI_THREAD_COMPRESSION
  292. struct list_head cbm_list;
  293. struct list_head *cbm_list_comp; /* cbm to compress */
  294. struct list_head *cbm_list_write; /* cbm to write */
  295. int cbm_list_comp_count; /* the number of cbm to compress */
  296. int cbm_list_write_count; /* the number of cbm to write */
  297. struct list_head mtc_list;
  298. int is_inserted_to_sii_list;
  299. #endif
  300. struct inode vfs_inode;
  301. /* DO NOT ADD FIELDS BELOW vfs_inode */
  302. };
  303. struct scfs_file_info
  304. {
  305. struct file *lower_file;
  306. };
  307. struct scfs_dentry_info
  308. {
  309. spinlock_t lock;
  310. struct path lower_path;
  311. };
  312. /**************************/
  313. /* macro helper functions */
  314. /**************************/
  315. #define SCFS_S(sb) ((struct scfs_sb_info *)(sb->s_fs_info))
  316. #define SCFS_I(inode) (container_of(inode, struct scfs_inode_info, vfs_inode))
  317. #define SCFS_F(file) ((struct scfs_file_info *)(file->private_data))
  318. #define SCFS_D(dent) ((struct scfs_dentry_info *)(dent->d_fsdata))
  319. #define CF_SIZE sizeof(struct comp_footer)
  320. #define IS_COMPRESSABLE(sii) (sii->flags & SCFS_DATA_COMPRESSABLE)
  321. #define IS_INVALID_META(sii) (sii->flags & SCFS_INVALID_META)
  322. #define IS_WROPENED(sii) (sii->flags & SCFS_WRITE_OPENED)
  323. #define MAKE_META_INVALID(sii) (sii->flags |= SCFS_INVALID_META)
  324. #define MAKE_WROPENED(sii) (sii->flags |= SCFS_WRITE_OPENED)
  325. #define CLEAR_META_INVALID(sii) (sii->flags &= ~SCFS_INVALID_META)
  326. #define CLEAR_WROPENED(sii) (sii->flags &= ~SCFS_WRITE_OPENED)
  327. #define CLUSTER_COUNT(sii) \
  328. DIV_ROUND_UP_ULL(i_size_read(&sii->vfs_inode), sii->cluster_size)
  329. #define PGOFF_IN_CLUSTER(page, sii) \
  330. (page->index % (sii->cluster_size / PAGE_SIZE))
  331. #define IS_CLUSTER_EXIST(sii, idx) \
  332. (sii->cinfo_array_size != 0 && \
  333. (idx+1) * sizeof(struct scfs_cinfo) <= sii->cinfo_array_size)
  334. #define PAGE_TO_CLUSTER_INDEX(page, sii) \
  335. ((page->index) / (sii->cluster_size / PAGE_SIZE))
  336. #define ASSERT(x) { \
  337. if (!(x)) { \
  338. printk(KERN_ERR "assertion %s failed: file %s line %d\n", #x,\
  339. __FILE__, __LINE__);\
  340. BUG(); \
  341. }\
  342. }
  343. #ifdef SCFS_DEBUG
  344. #define SCFS_PRINT(fmt, arg...) \
  345. scfs_printk(KERN_INFO "[SCFS] %s: " fmt, __func__, ## arg)
  346. #define SCFS_PRINT_WARN(fmt, arg...) \
  347. scfs_printk(KERN_WARNING "[SCFS] WARN %s: " fmt, __func__, ## arg)
  348. #define SCFS_DEBUG_START SCFS_PRINT("_start_\n")
  349. #define SCFS_DEBUG_END SCFS_PRINT("_end_\n")
  350. #else
  351. #define SCFS_PRINT(fmt, arg...)
  352. #define SCFS_PRINT_WARN(fmt, arg...)
  353. #define SCFS_DEBUG_START
  354. #define SCFS_DEBUG_END
  355. #endif
  356. #define SCFS_PRINT_ERROR(fmt, arg...) \
  357. scfs_printk(KERN_ERR "[SCFS] ERROR %s(%d): " fmt, __func__, __LINE__, ## arg)
  358. #define SCFS_PRINT_ALWAYS(fmt, arg...) \
  359. scfs_printk(KERN_ERR "[SCFS] %s(%d): " fmt, __func__,__LINE__, ## arg)
  360. #define list_to_page(head) (list_entry((head)->prev, struct page, lru))
  361. /********************/
  362. /* inline functions */
  363. /********************/
  364. #ifdef SCFS_PROFILE
  365. static struct timeval start_time;
  366. static struct timeval end_time;
  367. static inline void
  368. scfs_start_profile(struct timeval *start_time)
  369. {
  370. do_gettimeofday(start_time);
  371. }
  372. static inline void
  373. scfs_end_profile(struct timeval *end_time)
  374. {
  375. do_gettimeofday(end_time);
  376. }
  377. #define SCFS_START_PROFILE(start_time) \
  378. scfs_start_profile(start_time);
  379. #define SCFS_END_PROFILE(start, end, target) \
  380. scfs_end_profile(end); \
  381. *target += timeval_compare(end, start);
  382. // printk(KERN_ERR "%s in %s(%d): %lld.%06lld seconds elapsed\n",fmt,__FUNCTION__, __LINE__
  383. // , (long long)(end_time.tv_sec - start_time.tv_sec), (long long)(end_time.tv_usec - start_time.tv_usec));
  384. #else
  385. #define SCFS_START_PROFILE()
  386. #define SCFS_END_PROFILE(fmt)
  387. static inline void scfs_start_profile(void) { }
  388. static inline void scfs_end_profile(void) { }
  389. #endif
  390. static inline struct dentry *scfs_lower_dentry(struct dentry *dentry)
  391. {
  392. return ((struct scfs_dentry_info *)dentry->d_fsdata)->lower_path.dentry;
  393. }
  394. static inline void scfs_set_lower_dentry(struct dentry *dentry,
  395. struct dentry *lower_dentry)
  396. {
  397. ((struct scfs_dentry_info*)dentry->d_fsdata)->lower_path.dentry = lower_dentry;
  398. }
  399. static inline struct inode *scfs_lower_inode(const struct inode *i)
  400. {
  401. return SCFS_I(i)->lower_inode;
  402. }
  403. static inline void scfs_set_lower_inode(struct inode *i, struct inode *val)
  404. {
  405. SCFS_I(i)->lower_inode = val;
  406. }
  407. static inline struct file *scfs_lower_file(const struct file *f)
  408. {
  409. return SCFS_F(f)->lower_file;
  410. }
  411. static inline void scfs_set_lower_file(struct file *f, struct file *val)
  412. {
  413. SCFS_F(f)->lower_file = val;
  414. }
  415. static inline struct super_block *scfs_lower_super(const struct super_block *sb)
  416. {
  417. return SCFS_S(sb)->lower_sb;
  418. }
  419. static inline void scfs_set_lower_super(struct super_block *sb,
  420. struct super_block *val)
  421. {
  422. SCFS_S(sb)->lower_sb = val;
  423. }
  424. static inline struct vfsmount *scfs_dentry_to_lower_mnt(struct dentry *dentry)
  425. {
  426. return ((struct scfs_dentry_info *)dentry->d_fsdata)->lower_path.mnt;
  427. }
  428. static inline void scfs_set_dentry_lower_mnt(struct dentry *dentry,
  429. struct vfsmount *lower_mnt)
  430. {
  431. ((struct scfs_dentry_info *)dentry->d_fsdata)->lower_path.mnt = lower_mnt;
  432. }
  433. #ifdef SCFS_PROFILE_MEM
  434. static inline void profile_add_mempooled(int size, struct scfs_sb_info *sbi)
  435. {
  436. atomic_add(size, &sbi->mempooled_size);
  437. }
  438. static inline void profile_add_kmalloced(int size, struct scfs_sb_info *sbi)
  439. {
  440. atomic_add(size, &sbi->kmalloced_size);
  441. }
  442. static inline void profile_add_vmalloced(int size, struct scfs_sb_info *sbi)
  443. {
  444. atomic_add(size, &sbi->vmalloced_size);
  445. }
  446. static inline void profile_add_kmcached(int size, struct scfs_sb_info *sbi)
  447. {
  448. atomic_add(size, &sbi->kmcached_size);
  449. }
  450. static inline void profile_sub_mempooled(int size, struct scfs_sb_info *sbi)
  451. {
  452. atomic_sub(size, &sbi->mempooled_size);
  453. }
  454. static inline void profile_sub_kmalloced(int size, struct scfs_sb_info *sbi)
  455. {
  456. atomic_add(size, &sbi->kmalloced_size);
  457. }
  458. static inline void profile_sub_vmalloced(int size, struct scfs_sb_info *sbi)
  459. {
  460. atomic_sub(size, &sbi->vmalloced_size);
  461. }
  462. static inline void profile_sub_kmcached(int size, struct scfs_sb_info *sbi)
  463. {
  464. atomic_sub(size, &sbi->kmcached_size);
  465. }
  466. #else
  467. static inline void profile_add_mempooled(int size, struct scfs_sb_info *sbi) {}
  468. static inline void profile_add_kmalloced(int size, struct scfs_sb_info *sbi) {}
  469. static inline void profile_add_vmalloced(int size, struct scfs_sb_info *sbi) {}
  470. static inline void profile_add_kmcached(int size, struct scfs_sb_info *sbi) {}
  471. static inline void profile_sub_mempooled(int size, struct scfs_sb_info *sbi) {}
  472. static inline void profile_sub_kmalloced(int size, struct scfs_sb_info *sbi) {}
  473. static inline void profile_sub_vmalloced(int size, struct scfs_sb_info *sbi) {}
  474. static inline void profile_sub_kmcached(int size, struct scfs_sb_info *sbi) {}
  475. #endif
  476. /***********************/
  477. /* function prototypes */
  478. /***********************/
  479. void scfs_printk(const char *fmt, ...);
  480. int __init scfs_init_kthread(void);
  481. void scfs_destroy_kthread(void);
  482. int scfs_init_kmem_caches(void);
  483. void scfs_free_kmem_caches(void);
  484. int scfs_parse_options(struct scfs_sb_info *sbi, char *options);
  485. struct inode *scfs_get_inode(struct inode *lower_inode, struct super_block *sb);
  486. void copy_mount_flags_to_inode_flags(struct inode *inode, struct super_block *sb);
  487. int scfs_get_lower_file(struct dentry *dentry, struct inode *inode, int flags);
  488. void scfs_put_lower_file(struct inode *inode);
  489. int get_cluster_info(struct file *file, int cluster_n, struct scfs_cinfo *target);
  490. int get_cluster_info_from_list(struct inode *inode, int cluster_n,
  491. struct scfs_cinfo *target);
  492. int scfs_truncate(struct dentry *dentry, loff_t size);
  493. int scfs_read_cluster(struct file *file, struct page *page, char *buf_c,
  494. char **buf_u, int *compressed);
  495. int scfs_decompress(enum comp_type algo, char *buf_c, char *buf_u,
  496. size_t len, size_t *actual);
  497. int scfs_compress(enum comp_type algo, char *buf_c, char *buf_u, size_t len,
  498. size_t *actual, void *workdata, struct scfs_sb_info *sbi);
  499. struct page *scfs_alloc_mempool_buffer(struct scfs_sb_info *sbi);
  500. void scfs_free_mempool_buffer(struct page *p, struct scfs_sb_info *sbi);
  501. struct scfs_cluster_buffer *scfs_get_cluster_buffer(struct page *page,
  502. struct scfs_inode_info *sii, struct file *file);
  503. int scfs_get_comp_buffer(struct scfs_inode_info *sii);
  504. struct scfs_cluster_buffer *scfs_alloc_cluster_buffer(unsigned int cluster_idx,
  505. struct scfs_inode_info *sii);
  506. int scfs_check_space(struct scfs_sb_info *sbi, struct dentry *dentry);
  507. void sync_page_to_buffer(struct page *page, char *buffer);
  508. void sync_page_from_buffer(struct page *page, char *buffer);
  509. int scfs_check_ready_to_comp(struct scfs_cluster_buffer *cluster_buffer);
  510. int scfs_check_ready_to_write(struct scfs_cluster_buffer *cluster_buffer,
  511. struct scfs_inode_info *sii);
  512. void scfs_free_cluster_buffer(struct scfs_cluster_buffer *cluster_buffer);
  513. unsigned int scfs_get_lower_offset(unsigned int cluster_index,
  514. struct scfs_inode_info *sii);
  515. int scfs_get_cluster_from_lower(struct file *lower_file, struct scfs_cinfo clust_info);
  516. struct cinfo_entry *scfs_alloc_cinfo_entry(unsigned int cluster_index,
  517. struct scfs_inode_info *sii);
  518. int scfs_write_pending_cluster_buffer(struct scfs_cluster_buffer *cluster_buffer,
  519. struct file *lower_file, struct scfs_inode_info *sii);
  520. int scfs_write_cinfo(struct scfs_inode_info *sii, struct file *lower_file, loff_t *pos);
  521. int scfs_write_meta(struct file *file);
  522. ssize_t scfs_getxattr_lower(struct dentry *lower_dentry, const char *name,
  523. void *value, size_t size);
  524. int scfs_footer_read(struct inode *inode, struct file *lower_file);
  525. int scfs_reload_meta(struct file *file);
  526. int scfs_initialize_file(struct dentry *scfs_dentry, struct inode *scfs_inode);
  527. ssize_t scfs_lower_read(struct file *file, char *buf, size_t count, loff_t *pos);
  528. ssize_t scfs_lower_write(struct file *file, char *buf, size_t count, loff_t *pos);
  529. void *scfs_cinfo_alloc(struct scfs_inode_info *sii, unsigned long size);
  530. void scfs_cinfo_free(struct scfs_inode_info *sii, const void *addr);
  531. int scfs_initialize_lower_file(struct dentry *dentry, struct file **lower_file, int flags);
  532. int scfs_make_header(struct file *lower_file, struct inode *scfs_inode);
  533. int scfs_load_cinfo(struct scfs_inode_info *sii, struct file *lower_file);
  534. int scfs_check_cinfo(struct scfs_inode_info *sii, void *buf);
  535. #ifdef SCFS_ASYNC_READ_PAGES
  536. void wakeup_smb_thread(struct scfs_sb_info *sbi);
  537. int smb_init(struct scfs_sb_info *sbi);
  538. void smb_destroy(struct scfs_sb_info *sbi);
  539. int smb_thread(void *data);
  540. #endif
  541. #ifdef SCFS_MULTI_THREAD_COMPRESSION
  542. extern void wakeup_smtc_thread(struct scfs_sb_info *sb_info);
  543. extern int smtc_init(struct scfs_sb_info *sbi);
  544. extern void smtc_destroy(struct scfs_sb_info *sbi);
  545. extern int smtc_thread(void *info);
  546. extern int scfs_compress_cluster(struct scfs_inode_info *sii,
  547. struct scfs_cluster_buffer_mtc *cbm, void *workdata);
  548. //extern int scfs_write_compress_all_cluster(struct scfs_inode_info *sii);
  549. extern int scfs_write_compress_all_cluster(struct scfs_inode_info *sii,
  550. struct file *lower_file);
  551. extern int scfs_write_one_compress_cluster(struct scfs_inode_info *sii,
  552. struct scfs_cluster_buffer_mtc *cbm);
  553. extern int smtc_writer_thread(void *info);
  554. extern void wakeup_smtc_writer_thread(struct scfs_sb_info *sb_info);
  555. #endif
  556. /* compressor.c */
  557. int scfs_compressors_init(void);
  558. void scfs_compressors_exit(void);
  559. int scfs_compress_crypto(const void *in_buf, size_t in_len, void *out_buf, size_t *out_len,
  560. int compr_type);
  561. int scfs_decompress_crypto(const void *buf, size_t len, void *out, size_t *out_len,
  562. int compr_type);
  563. #endif //SCFS_HEADER_H