netfs.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920
  1. /*
  2. * 2007+ Copyright (c) Evgeniy Polyakov <zbr@ioremap.net>
  3. * All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program 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. #ifndef __NETFS_H
  16. #define __NETFS_H
  17. #include <linux/types.h>
  18. #include <linux/connector.h>
  19. #include <linux/backing-dev.h>
  20. #define POHMELFS_CN_IDX 5
  21. #define POHMELFS_CN_VAL 0
  22. #define POHMELFS_CTLINFO_ACK 1
  23. #define POHMELFS_NOINFO_ACK 2
  24. #define POHMELFS_NULL_IDX 65535
  25. /*
  26. * Network command structure.
  27. * Will be extended.
  28. */
  29. struct netfs_cmd {
  30. __u16 cmd; /* Command number */
  31. __u16 csize; /* Attached crypto information size */
  32. __u16 cpad; /* Attached padding size */
  33. __u16 ext; /* External flags */
  34. __u32 size; /* Size of the attached data */
  35. __u32 trans; /* Transaction id */
  36. __u64 id; /* Object ID to operate on. Used for feedback.*/
  37. __u64 start; /* Start of the object. */
  38. __u64 iv; /* IV sequence */
  39. __u8 data[0];
  40. };
  41. static inline void netfs_convert_cmd(struct netfs_cmd *cmd)
  42. {
  43. cmd->id = __be64_to_cpu(cmd->id);
  44. cmd->start = __be64_to_cpu(cmd->start);
  45. cmd->iv = __be64_to_cpu(cmd->iv);
  46. cmd->cmd = __be16_to_cpu(cmd->cmd);
  47. cmd->ext = __be16_to_cpu(cmd->ext);
  48. cmd->csize = __be16_to_cpu(cmd->csize);
  49. cmd->cpad = __be16_to_cpu(cmd->cpad);
  50. cmd->size = __be32_to_cpu(cmd->size);
  51. }
  52. #define NETFS_TRANS_SINGLE_DST (1<<0)
  53. enum {
  54. NETFS_READDIR = 1, /* Read directory for given inode number */
  55. NETFS_READ_PAGE, /* Read data page from the server */
  56. NETFS_WRITE_PAGE, /* Write data page to the server */
  57. NETFS_CREATE, /* Create directory entry */
  58. NETFS_REMOVE, /* Remove directory entry */
  59. NETFS_LOOKUP, /* Lookup single object */
  60. NETFS_LINK, /* Create a link */
  61. NETFS_TRANS, /* Transaction */
  62. NETFS_OPEN, /* Open intent */
  63. NETFS_INODE_INFO, /* Metadata cache coherency synchronization message */
  64. NETFS_PAGE_CACHE, /* Page cache invalidation message */
  65. NETFS_READ_PAGES, /* Read multiple contiguous pages in one go */
  66. NETFS_RENAME, /* Rename object */
  67. NETFS_CAPABILITIES, /* Capabilities of the client, for example supported crypto */
  68. NETFS_LOCK, /* Distributed lock message */
  69. NETFS_XATTR_SET, /* Set extended attribute */
  70. NETFS_XATTR_GET, /* Get extended attribute */
  71. NETFS_CMD_MAX
  72. };
  73. enum {
  74. POHMELFS_FLAGS_ADD = 0, /* Network state control message for ADD */
  75. POHMELFS_FLAGS_DEL, /* Network state control message for DEL */
  76. POHMELFS_FLAGS_SHOW, /* Network state control message for SHOW */
  77. POHMELFS_FLAGS_CRYPTO, /* Crypto data control message */
  78. POHMELFS_FLAGS_MODIFY, /* Network state modification message */
  79. POHMELFS_FLAGS_DUMP, /* Network state control message for SHOW ALL */
  80. POHMELFS_FLAGS_FLUSH, /* Network state control message for FLUSH */
  81. };
  82. /*
  83. * Always wanted to copy it from socket headers into public one,
  84. * since they are __KERNEL__ protected there.
  85. */
  86. #define _K_SS_MAXSIZE 128
  87. struct saddr {
  88. unsigned short sa_family;
  89. char addr[_K_SS_MAXSIZE];
  90. };
  91. enum {
  92. POHMELFS_CRYPTO_HASH = 0,
  93. POHMELFS_CRYPTO_CIPHER,
  94. };
  95. struct pohmelfs_crypto {
  96. unsigned int idx; /* Config index */
  97. unsigned short strlen; /* Size of the attached crypto string including 0-byte
  98. * "cbc(aes)" for example */
  99. unsigned short type; /* HMAC, cipher, both */
  100. unsigned int keysize; /* Key size */
  101. unsigned char data[0]; /* Algorithm string, key and IV */
  102. };
  103. #define POHMELFS_IO_PERM_READ (1<<0)
  104. #define POHMELFS_IO_PERM_WRITE (1<<1)
  105. /*
  106. * Configuration command used to create table of different remote servers.
  107. */
  108. struct pohmelfs_ctl {
  109. __u32 idx; /* Config index */
  110. __u32 type; /* Socket type */
  111. __u32 proto; /* Socket protocol */
  112. __u16 addrlen; /* Size of the address */
  113. __u16 perm; /* IO permission */
  114. __u16 prio; /* IO priority */
  115. struct saddr addr; /* Remote server address */
  116. };
  117. /*
  118. * Ack for userspace about requested command.
  119. */
  120. struct pohmelfs_cn_ack {
  121. struct cn_msg msg;
  122. int error;
  123. int msg_num;
  124. int unused[3];
  125. struct pohmelfs_ctl ctl;
  126. };
  127. /*
  128. * Inode info structure used to sync with server.
  129. * Check what stat() returns.
  130. */
  131. struct netfs_inode_info {
  132. unsigned int mode;
  133. unsigned int nlink;
  134. unsigned int uid;
  135. unsigned int gid;
  136. unsigned int blocksize;
  137. unsigned int padding;
  138. __u64 ino;
  139. __u64 blocks;
  140. __u64 rdev;
  141. __u64 size;
  142. __u64 version;
  143. };
  144. static inline void netfs_convert_inode_info(struct netfs_inode_info *info)
  145. {
  146. info->mode = __cpu_to_be32(info->mode);
  147. info->nlink = __cpu_to_be32(info->nlink);
  148. info->uid = __cpu_to_be32(info->uid);
  149. info->gid = __cpu_to_be32(info->gid);
  150. info->blocksize = __cpu_to_be32(info->blocksize);
  151. info->blocks = __cpu_to_be64(info->blocks);
  152. info->rdev = __cpu_to_be64(info->rdev);
  153. info->size = __cpu_to_be64(info->size);
  154. info->version = __cpu_to_be64(info->version);
  155. info->ino = __cpu_to_be64(info->ino);
  156. }
  157. /*
  158. * Cache state machine.
  159. */
  160. enum {
  161. NETFS_COMMAND_PENDING = 0, /* Command is being executed */
  162. NETFS_INODE_REMOTE_SYNCED, /* Inode was synced to server */
  163. NETFS_INODE_REMOTE_DIR_SYNCED, /* Inode (directory) was synced from the server */
  164. NETFS_INODE_OWNED, /* Inode is owned by given host */
  165. NETFS_INODE_NEED_FLUSH, /* Inode has to be flushed to the server */
  166. };
  167. /*
  168. * POHMELFS capabilities: information about supported
  169. * crypto operations (hash/cipher, modes, key sizes and so on),
  170. * root information (used/available size, number of objects, permissions)
  171. */
  172. enum pohmelfs_capabilities {
  173. POHMELFS_CRYPTO_CAPABILITIES = 0,
  174. POHMELFS_ROOT_CAPABILITIES,
  175. };
  176. /* Read-only mount */
  177. #define POHMELFS_FLAGS_RO (1<<0)
  178. /* Extended attributes support on/off */
  179. #define POHMELFS_FLAGS_XATTR (1<<1)
  180. struct netfs_root_capabilities {
  181. __u64 nr_files;
  182. __u64 used, avail;
  183. __u64 flags;
  184. };
  185. static inline void netfs_convert_root_capabilities(struct netfs_root_capabilities *cap)
  186. {
  187. cap->nr_files = __cpu_to_be64(cap->nr_files);
  188. cap->used = __cpu_to_be64(cap->used);
  189. cap->avail = __cpu_to_be64(cap->avail);
  190. cap->flags = __cpu_to_be64(cap->flags);
  191. }
  192. struct netfs_crypto_capabilities {
  193. unsigned short hash_strlen; /* Hash string length, like "hmac(sha1) including 0 byte "*/
  194. unsigned short cipher_strlen; /* Cipher string length with the same format */
  195. unsigned int cipher_keysize; /* Cipher key size */
  196. };
  197. static inline void netfs_convert_crypto_capabilities(struct netfs_crypto_capabilities *cap)
  198. {
  199. cap->hash_strlen = __cpu_to_be16(cap->hash_strlen);
  200. cap->cipher_strlen = __cpu_to_be16(cap->cipher_strlen);
  201. cap->cipher_keysize = __cpu_to_be32(cap->cipher_keysize);
  202. }
  203. enum pohmelfs_lock_type {
  204. POHMELFS_LOCK_GRAB = (1<<15),
  205. POHMELFS_READ_LOCK = 0,
  206. POHMELFS_WRITE_LOCK,
  207. };
  208. struct netfs_lock {
  209. __u64 start;
  210. __u64 ino;
  211. __u32 size;
  212. __u32 type;
  213. };
  214. static inline void netfs_convert_lock(struct netfs_lock *lock)
  215. {
  216. lock->start = __cpu_to_be64(lock->start);
  217. lock->ino = __cpu_to_be64(lock->ino);
  218. lock->size = __cpu_to_be32(lock->size);
  219. lock->type = __cpu_to_be32(lock->type);
  220. }
  221. #ifdef __KERNEL__
  222. #include <linux/kernel.h>
  223. #include <linux/completion.h>
  224. #include <linux/rbtree.h>
  225. #include <linux/net.h>
  226. #include <linux/poll.h>
  227. /*
  228. * Private POHMELFS cache of objects in directory.
  229. */
  230. struct pohmelfs_name {
  231. struct rb_node hash_node;
  232. struct list_head sync_create_entry;
  233. u64 ino;
  234. u32 hash;
  235. u32 mode;
  236. u32 len;
  237. char *data;
  238. };
  239. /*
  240. * POHMELFS inode. Main object.
  241. */
  242. struct pohmelfs_inode {
  243. struct list_head inode_entry; /* Entry in superblock list.
  244. * Objects which are not bound to dentry require to be dropped
  245. * in ->put_super()
  246. */
  247. struct rb_root hash_root; /* The same, but indexed by name hash and len */
  248. struct mutex offset_lock; /* Protect both above trees */
  249. struct list_head sync_create_list; /* List of created but not yet synced to the server children */
  250. unsigned int drop_count;
  251. int lock_type; /* How this inode is locked: read or write */
  252. int error; /* Transaction error for given inode */
  253. long state; /* State machine above */
  254. u64 ino; /* Inode number */
  255. u64 total_len; /* Total length of all children names, used to create offsets */
  256. struct inode vfs_inode;
  257. };
  258. struct netfs_trans;
  259. typedef int (*netfs_trans_complete_t)(struct page **pages, unsigned int page_num,
  260. void *private, int err);
  261. struct netfs_state;
  262. struct pohmelfs_sb;
  263. struct netfs_trans {
  264. /*
  265. * Transaction header and attached contiguous data live here.
  266. */
  267. struct iovec iovec;
  268. /*
  269. * Pages attached to transaction.
  270. */
  271. struct page **pages;
  272. /*
  273. * List and protecting lock for transaction destination
  274. * network states.
  275. */
  276. spinlock_t dst_lock;
  277. struct list_head dst_list;
  278. /*
  279. * Number of users for given transaction.
  280. * For example each network state attached to transaction
  281. * via dst_list increases it.
  282. */
  283. atomic_t refcnt;
  284. /*
  285. * Number of pages attached to given transaction.
  286. * Some slots in above page array can be NULL, since
  287. * for example page can be under writeback already,
  288. * so we skip it in this transaction.
  289. */
  290. unsigned int page_num;
  291. /*
  292. * Transaction flags: single dst or broadcast and so on.
  293. */
  294. unsigned int flags;
  295. /*
  296. * Size of the data, which can be placed into
  297. * iovec.iov_base area.
  298. */
  299. unsigned int total_size;
  300. /*
  301. * Number of pages to be sent to remote server.
  302. * Usually equal to above page_num, but in case of partial
  303. * writeback it can accumulate only pages already completed
  304. * previous writeback.
  305. */
  306. unsigned int attached_pages;
  307. /*
  308. * Attached number of bytes in all above pages.
  309. */
  310. unsigned int attached_size;
  311. /*
  312. * Unique transacton generation number.
  313. * Used as identity in the network state tree of transactions.
  314. */
  315. unsigned int gen;
  316. /*
  317. * Transaction completion status.
  318. */
  319. int result;
  320. /*
  321. * Superblock this transaction belongs to
  322. */
  323. struct pohmelfs_sb *psb;
  324. /*
  325. * Crypto engine, which processed this transaction.
  326. * Can be not NULL only if crypto engine holds encrypted pages.
  327. */
  328. struct pohmelfs_crypto_engine *eng;
  329. /* Private data */
  330. void *private;
  331. /* Completion callback, invoked just before transaction is destroyed */
  332. netfs_trans_complete_t complete;
  333. };
  334. static inline int netfs_trans_cur_len(struct netfs_trans *t)
  335. {
  336. return (signed)(t->total_size - t->iovec.iov_len);
  337. }
  338. static inline void *netfs_trans_current(struct netfs_trans *t)
  339. {
  340. return t->iovec.iov_base + t->iovec.iov_len;
  341. }
  342. struct netfs_trans *netfs_trans_alloc(struct pohmelfs_sb *psb, unsigned int size,
  343. unsigned int flags, unsigned int nr);
  344. void netfs_trans_free(struct netfs_trans *t);
  345. int netfs_trans_finish(struct netfs_trans *t, struct pohmelfs_sb *psb);
  346. int netfs_trans_finish_send(struct netfs_trans *t, struct pohmelfs_sb *psb);
  347. static inline void netfs_trans_reset(struct netfs_trans *t)
  348. {
  349. t->complete = NULL;
  350. }
  351. struct netfs_trans_dst {
  352. struct list_head trans_entry;
  353. struct rb_node state_entry;
  354. unsigned long send_time;
  355. /*
  356. * Times this transaction was resent to its old or new,
  357. * depending on flags, destinations. When it reaches maximum
  358. * allowed number, specified in superblock->trans_retries,
  359. * transaction will be freed with ETIMEDOUT error.
  360. */
  361. unsigned int retries;
  362. struct netfs_trans *trans;
  363. struct netfs_state *state;
  364. };
  365. struct netfs_trans_dst *netfs_trans_search(struct netfs_state *st, unsigned int gen);
  366. void netfs_trans_drop_dst(struct netfs_trans_dst *dst);
  367. void netfs_trans_drop_dst_nostate(struct netfs_trans_dst *dst);
  368. void netfs_trans_drop_trans(struct netfs_trans *t, struct netfs_state *st);
  369. void netfs_trans_drop_last(struct netfs_trans *t, struct netfs_state *st);
  370. int netfs_trans_resend(struct netfs_trans *t, struct pohmelfs_sb *psb);
  371. int netfs_trans_remove_nolock(struct netfs_trans_dst *dst, struct netfs_state *st);
  372. int netfs_trans_init(void);
  373. void netfs_trans_exit(void);
  374. struct pohmelfs_crypto_engine {
  375. u64 iv; /* Crypto IV for current operation */
  376. unsigned long timeout; /* Crypto waiting timeout */
  377. unsigned int size; /* Size of crypto scratchpad */
  378. void *data; /* Temporal crypto scratchpad */
  379. /*
  380. * Crypto operations performed on objects.
  381. */
  382. struct crypto_hash *hash;
  383. struct crypto_ablkcipher *cipher;
  384. struct pohmelfs_crypto_thread *thread; /* Crypto thread which hosts this engine */
  385. struct page **pages;
  386. unsigned int page_num;
  387. };
  388. struct pohmelfs_crypto_thread {
  389. struct list_head thread_entry;
  390. struct task_struct *thread;
  391. struct pohmelfs_sb *psb;
  392. struct pohmelfs_crypto_engine eng;
  393. struct netfs_trans *trans;
  394. wait_queue_head_t wait;
  395. int error;
  396. unsigned int size;
  397. struct page *page;
  398. };
  399. void pohmelfs_crypto_thread_make_ready(struct pohmelfs_crypto_thread *th);
  400. /*
  401. * Network state, attached to one server.
  402. */
  403. struct netfs_state {
  404. struct mutex __state_lock; /* Can not allow to use the same socket simultaneously */
  405. struct mutex __state_send_lock;
  406. struct netfs_cmd cmd; /* Cached command */
  407. struct netfs_inode_info info; /* Cached inode info */
  408. void *data; /* Cached some data */
  409. unsigned int size; /* Size of that data */
  410. struct pohmelfs_sb *psb; /* Superblock */
  411. struct task_struct *thread; /* Async receiving thread */
  412. /* Waiting/polling machinery */
  413. wait_queue_t wait;
  414. wait_queue_head_t *whead;
  415. wait_queue_head_t thread_wait;
  416. struct mutex trans_lock;
  417. struct rb_root trans_root;
  418. struct pohmelfs_ctl ctl; /* Remote peer */
  419. struct socket *socket; /* Socket object */
  420. struct socket *read_socket; /* Cached pointer to socket object.
  421. * Used to determine if between lock drops socket was changed.
  422. * Never used to read data or any kind of access.
  423. */
  424. /*
  425. * Crypto engines to process incoming data.
  426. */
  427. struct pohmelfs_crypto_engine eng;
  428. int need_reset;
  429. };
  430. int netfs_state_init(struct netfs_state *st);
  431. void netfs_state_exit(struct netfs_state *st);
  432. static inline void netfs_state_lock_send(struct netfs_state *st)
  433. {
  434. mutex_lock(&st->__state_send_lock);
  435. }
  436. static inline int netfs_state_trylock_send(struct netfs_state *st)
  437. {
  438. return mutex_trylock(&st->__state_send_lock);
  439. }
  440. static inline void netfs_state_unlock_send(struct netfs_state *st)
  441. {
  442. BUG_ON(!mutex_is_locked(&st->__state_send_lock));
  443. mutex_unlock(&st->__state_send_lock);
  444. }
  445. static inline void netfs_state_lock(struct netfs_state *st)
  446. {
  447. mutex_lock(&st->__state_lock);
  448. }
  449. static inline void netfs_state_unlock(struct netfs_state *st)
  450. {
  451. BUG_ON(!mutex_is_locked(&st->__state_lock));
  452. mutex_unlock(&st->__state_lock);
  453. }
  454. static inline unsigned int netfs_state_poll(struct netfs_state *st)
  455. {
  456. unsigned int revents = POLLHUP | POLLERR;
  457. netfs_state_lock(st);
  458. if (st->socket)
  459. revents = st->socket->ops->poll(NULL, st->socket, NULL);
  460. netfs_state_unlock(st);
  461. return revents;
  462. }
  463. struct pohmelfs_config;
  464. struct pohmelfs_sb {
  465. struct rb_root mcache_root;
  466. struct mutex mcache_lock;
  467. atomic_long_t mcache_gen;
  468. unsigned long mcache_timeout;
  469. unsigned int idx;
  470. unsigned int trans_retries;
  471. atomic_t trans_gen;
  472. unsigned int crypto_attached_size;
  473. unsigned int crypto_align_size;
  474. unsigned int crypto_fail_unsupported;
  475. unsigned int crypto_thread_num;
  476. struct list_head crypto_active_list, crypto_ready_list;
  477. struct mutex crypto_thread_lock;
  478. unsigned int trans_max_pages;
  479. unsigned long trans_data_size;
  480. unsigned long trans_timeout;
  481. unsigned long drop_scan_timeout;
  482. unsigned long trans_scan_timeout;
  483. unsigned long wait_on_page_timeout;
  484. struct list_head flush_list;
  485. struct list_head drop_list;
  486. spinlock_t ino_lock;
  487. u64 ino;
  488. /*
  489. * Remote nodes POHMELFS connected to.
  490. */
  491. struct list_head state_list;
  492. struct mutex state_lock;
  493. /*
  494. * Currently active state to request data from.
  495. */
  496. struct pohmelfs_config *active_state;
  497. wait_queue_head_t wait;
  498. /*
  499. * Timed checks: stale transactions, inodes to be freed and so on.
  500. */
  501. struct delayed_work dwork;
  502. struct delayed_work drop_dwork;
  503. struct super_block *sb;
  504. struct backing_dev_info bdi;
  505. /*
  506. * Algorithm strings.
  507. */
  508. char *hash_string;
  509. char *cipher_string;
  510. u8 *hash_key;
  511. u8 *cipher_key;
  512. /*
  513. * Algorithm string lengths.
  514. */
  515. unsigned int hash_strlen;
  516. unsigned int cipher_strlen;
  517. unsigned int hash_keysize;
  518. unsigned int cipher_keysize;
  519. /*
  520. * Controls whether to perfrom crypto processing or not.
  521. */
  522. int perform_crypto;
  523. /*
  524. * POHMELFS statistics.
  525. */
  526. u64 total_size;
  527. u64 avail_size;
  528. atomic_long_t total_inodes;
  529. /*
  530. * Xattr support, read-only and so on.
  531. */
  532. u64 state_flags;
  533. /*
  534. * Temporary storage to detect changes in the wait queue.
  535. */
  536. long flags;
  537. };
  538. static inline void netfs_trans_update(struct netfs_cmd *cmd,
  539. struct netfs_trans *t, unsigned int size)
  540. {
  541. unsigned int sz = ALIGN(size, t->psb->crypto_align_size);
  542. t->iovec.iov_len += sizeof(struct netfs_cmd) + sz;
  543. cmd->cpad = __cpu_to_be16(sz - size);
  544. }
  545. static inline struct pohmelfs_sb *POHMELFS_SB(struct super_block *sb)
  546. {
  547. return sb->s_fs_info;
  548. }
  549. static inline struct pohmelfs_inode *POHMELFS_I(struct inode *inode)
  550. {
  551. return container_of(inode, struct pohmelfs_inode, vfs_inode);
  552. }
  553. static inline u64 pohmelfs_new_ino(struct pohmelfs_sb *psb)
  554. {
  555. u64 ino;
  556. spin_lock(&psb->ino_lock);
  557. ino = psb->ino++;
  558. spin_unlock(&psb->ino_lock);
  559. return ino;
  560. }
  561. static inline void pohmelfs_put_inode(struct pohmelfs_inode *pi)
  562. {
  563. struct pohmelfs_sb *psb = POHMELFS_SB(pi->vfs_inode.i_sb);
  564. spin_lock(&psb->ino_lock);
  565. list_move_tail(&pi->inode_entry, &psb->drop_list);
  566. pi->drop_count++;
  567. spin_unlock(&psb->ino_lock);
  568. }
  569. struct pohmelfs_config {
  570. struct list_head config_entry;
  571. struct netfs_state state;
  572. };
  573. struct pohmelfs_config_group {
  574. /*
  575. * Entry in the global config group list.
  576. */
  577. struct list_head group_entry;
  578. /*
  579. * Index of the current group.
  580. */
  581. unsigned int idx;
  582. /*
  583. * Number of config_list entries in this group entry.
  584. */
  585. unsigned int num_entry;
  586. /*
  587. * Algorithm strings.
  588. */
  589. char *hash_string;
  590. char *cipher_string;
  591. /*
  592. * Algorithm string lengths.
  593. */
  594. unsigned int hash_strlen;
  595. unsigned int cipher_strlen;
  596. /*
  597. * Key and its size.
  598. */
  599. unsigned int hash_keysize;
  600. unsigned int cipher_keysize;
  601. u8 *hash_key;
  602. u8 *cipher_key;
  603. /*
  604. * List of config entries (network state info) for given idx.
  605. */
  606. struct list_head config_list;
  607. };
  608. int __init pohmelfs_config_init(void);
  609. void pohmelfs_config_exit(void);
  610. int pohmelfs_copy_config(struct pohmelfs_sb *psb);
  611. int pohmelfs_copy_crypto(struct pohmelfs_sb *psb);
  612. int pohmelfs_config_check(struct pohmelfs_config *config, int idx);
  613. int pohmelfs_state_init_one(struct pohmelfs_sb *psb, struct pohmelfs_config *conf);
  614. extern const struct file_operations pohmelfs_dir_fops;
  615. extern const struct inode_operations pohmelfs_dir_inode_ops;
  616. int pohmelfs_state_init(struct pohmelfs_sb *psb);
  617. void pohmelfs_state_exit(struct pohmelfs_sb *psb);
  618. void pohmelfs_state_flush_transactions(struct netfs_state *st);
  619. void pohmelfs_fill_inode(struct inode *inode, struct netfs_inode_info *info);
  620. void pohmelfs_name_del(struct pohmelfs_inode *parent, struct pohmelfs_name *n);
  621. void pohmelfs_free_names(struct pohmelfs_inode *parent);
  622. struct pohmelfs_name *pohmelfs_search_hash(struct pohmelfs_inode *pi, u32 hash);
  623. void pohmelfs_inode_del_inode(struct pohmelfs_sb *psb, struct pohmelfs_inode *pi);
  624. struct pohmelfs_inode *pohmelfs_create_entry_local(struct pohmelfs_sb *psb,
  625. struct pohmelfs_inode *parent, struct qstr *str, u64 start, int mode);
  626. int pohmelfs_write_create_inode(struct pohmelfs_inode *pi);
  627. int pohmelfs_write_inode_create(struct inode *inode, struct netfs_trans *trans);
  628. int pohmelfs_remove_child(struct pohmelfs_inode *parent, struct pohmelfs_name *n);
  629. struct pohmelfs_inode *pohmelfs_new_inode(struct pohmelfs_sb *psb,
  630. struct pohmelfs_inode *parent, struct qstr *str,
  631. struct netfs_inode_info *info, int link);
  632. int pohmelfs_setattr(struct dentry *dentry, struct iattr *attr);
  633. int pohmelfs_setattr_raw(struct inode *inode, struct iattr *attr);
  634. int pohmelfs_meta_command(struct pohmelfs_inode *pi, unsigned int cmd_op, unsigned int flags,
  635. netfs_trans_complete_t complete, void *priv, u64 start);
  636. int pohmelfs_meta_command_data(struct pohmelfs_inode *pi, u64 id, unsigned int cmd_op, char *addon,
  637. unsigned int flags, netfs_trans_complete_t complete, void *priv, u64 start);
  638. void pohmelfs_check_states(struct pohmelfs_sb *psb);
  639. void pohmelfs_switch_active(struct pohmelfs_sb *psb);
  640. int pohmelfs_construct_path_string(struct pohmelfs_inode *pi, void *data, int len);
  641. int pohmelfs_path_length(struct pohmelfs_inode *pi);
  642. struct pohmelfs_crypto_completion {
  643. struct completion complete;
  644. int error;
  645. };
  646. int pohmelfs_trans_crypt(struct netfs_trans *t, struct pohmelfs_sb *psb);
  647. void pohmelfs_crypto_exit(struct pohmelfs_sb *psb);
  648. int pohmelfs_crypto_init(struct pohmelfs_sb *psb);
  649. int pohmelfs_crypto_engine_init(struct pohmelfs_crypto_engine *e, struct pohmelfs_sb *psb);
  650. void pohmelfs_crypto_engine_exit(struct pohmelfs_crypto_engine *e);
  651. int pohmelfs_crypto_process_input_data(struct pohmelfs_crypto_engine *e, u64 iv,
  652. void *data, struct page *page, unsigned int size);
  653. int pohmelfs_crypto_process_input_page(struct pohmelfs_crypto_engine *e,
  654. struct page *page, unsigned int size, u64 iv);
  655. static inline u64 pohmelfs_gen_iv(struct netfs_trans *t)
  656. {
  657. u64 iv = t->gen;
  658. iv <<= 32;
  659. iv |= ((unsigned long)t) & 0xffffffff;
  660. return iv;
  661. }
  662. int pohmelfs_data_lock(struct pohmelfs_inode *pi, u64 start, u32 size, int type);
  663. int pohmelfs_data_unlock(struct pohmelfs_inode *pi, u64 start, u32 size, int type);
  664. int pohmelfs_data_lock_response(struct netfs_state *st);
  665. static inline int pohmelfs_need_lock(struct pohmelfs_inode *pi, int type)
  666. {
  667. if (test_bit(NETFS_INODE_OWNED, &pi->state)) {
  668. if (type == pi->lock_type)
  669. return 0;
  670. if ((type == POHMELFS_READ_LOCK) && (pi->lock_type == POHMELFS_WRITE_LOCK))
  671. return 0;
  672. }
  673. if (!test_bit(NETFS_INODE_REMOTE_SYNCED, &pi->state))
  674. return 0;
  675. return 1;
  676. }
  677. int __init pohmelfs_mcache_init(void);
  678. void pohmelfs_mcache_exit(void);
  679. /* #define CONFIG_POHMELFS_DEBUG */
  680. #ifdef CONFIG_POHMELFS_DEBUG
  681. #define dprintka(f, a...) printk(f, ##a)
  682. #define dprintk(f, a...) printk("%d: " f, task_pid_vnr(current), ##a)
  683. #else
  684. #define dprintka(f, a...) do {} while (0)
  685. #define dprintk(f, a...) do {} while (0)
  686. #endif
  687. static inline void netfs_trans_get(struct netfs_trans *t)
  688. {
  689. atomic_inc(&t->refcnt);
  690. }
  691. static inline void netfs_trans_put(struct netfs_trans *t)
  692. {
  693. if (atomic_dec_and_test(&t->refcnt)) {
  694. dprintk("%s: t: %p, gen: %u, err: %d.\n",
  695. __func__, t, t->gen, t->result);
  696. if (t->complete)
  697. t->complete(t->pages, t->page_num,
  698. t->private, t->result);
  699. netfs_trans_free(t);
  700. }
  701. }
  702. struct pohmelfs_mcache {
  703. struct rb_node mcache_entry;
  704. struct completion complete;
  705. atomic_t refcnt;
  706. u64 gen;
  707. void *data;
  708. u64 start;
  709. u32 size;
  710. int err;
  711. struct netfs_inode_info info;
  712. };
  713. struct pohmelfs_mcache *pohmelfs_mcache_alloc(struct pohmelfs_sb *psb, u64 start,
  714. unsigned int size, void *data);
  715. void pohmelfs_mcache_free(struct pohmelfs_sb *psb, struct pohmelfs_mcache *m);
  716. struct pohmelfs_mcache *pohmelfs_mcache_search(struct pohmelfs_sb *psb, u64 gen);
  717. void pohmelfs_mcache_remove_locked(struct pohmelfs_sb *psb, struct pohmelfs_mcache *m);
  718. static inline void pohmelfs_mcache_get(struct pohmelfs_mcache *m)
  719. {
  720. atomic_inc(&m->refcnt);
  721. }
  722. static inline void pohmelfs_mcache_put(struct pohmelfs_sb *psb,
  723. struct pohmelfs_mcache *m)
  724. {
  725. if (atomic_dec_and_test(&m->refcnt))
  726. pohmelfs_mcache_free(psb, m);
  727. }
  728. /*#define POHMELFS_TRUNCATE_ON_INODE_FLUSH
  729. */
  730. #endif /* __KERNEL__*/
  731. #endif /* __NETFS_H */