network_protocol.txt 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. POHMELFS network protocol.
  2. Basic structure used in network communication is following command:
  3. struct netfs_cmd
  4. {
  5. __u16 cmd; /* Command number */
  6. __u16 csize; /* Attached crypto information size */
  7. __u16 cpad; /* Attached padding size */
  8. __u16 ext; /* External flags */
  9. __u32 size; /* Size of the attached data */
  10. __u32 trans; /* Transaction id */
  11. __u64 id; /* Object ID to operate on. Used for feedback.*/
  12. __u64 start; /* Start of the object. */
  13. __u64 iv; /* IV sequence */
  14. __u8 data[0];
  15. };
  16. Commands can be embedded into transaction command (which in turn has own command),
  17. so one can extend protocol as needed without breaking backward compatibility as long
  18. as old commands are supported. All string lengths include tail 0 byte.
  19. All commands are transferred over the network in big-endian. CPU endianness is used at the end peers.
  20. @cmd - command number, which specifies command to be processed. Following
  21. commands are used currently:
  22. NETFS_READDIR = 1, /* Read directory for given inode number */
  23. NETFS_READ_PAGE, /* Read data page from the server */
  24. NETFS_WRITE_PAGE, /* Write data page to the server */
  25. NETFS_CREATE, /* Create directory entry */
  26. NETFS_REMOVE, /* Remove directory entry */
  27. NETFS_LOOKUP, /* Lookup single object */
  28. NETFS_LINK, /* Create a link */
  29. NETFS_TRANS, /* Transaction */
  30. NETFS_OPEN, /* Open intent */
  31. NETFS_INODE_INFO, /* Metadata cache coherency synchronization message */
  32. NETFS_PAGE_CACHE, /* Page cache invalidation message */
  33. NETFS_READ_PAGES, /* Read multiple contiguous pages in one go */
  34. NETFS_RENAME, /* Rename object */
  35. NETFS_CAPABILITIES, /* Capabilities of the client, for example supported crypto */
  36. NETFS_LOCK, /* Distributed lock message */
  37. NETFS_XATTR_SET, /* Set extended attribute */
  38. NETFS_XATTR_GET, /* Get extended attribute */
  39. @ext - external flags. Used by different commands to specify some extra arguments
  40. like partial size of the embedded objects or creation flags.
  41. @size - size of the attached data. For NETFS_READ_PAGE and NETFS_READ_PAGES no data is attached,
  42. but size of the requested data is incorporated here. It does not include size of the command
  43. header (struct netfs_cmd) itself.
  44. @id - id of the object this command operates on. Each command can use it for own purpose.
  45. @start - start of the object this command operates on. Each command can use it for own purpose.
  46. @csize, @cpad - size and padding size of the (attached if needed) crypto information.
  47. Command specifications.
  48. @NETFS_READDIR
  49. This command is used to sync content of the remote dir to the client.
  50. @ext - length of the path to object.
  51. @size - the same.
  52. @id - local inode number of the directory to read.
  53. @start - zero.
  54. @NETFS_READ_PAGE
  55. This command is used to read data from remote server.
  56. Data size does not exceed local page cache size.
  57. @id - inode number.
  58. @start - first byte offset.
  59. @size - number of bytes to read plus length of the path to object.
  60. @ext - object path length.
  61. @NETFS_CREATE
  62. Used to create object.
  63. It does not require that all directories on top of the object were
  64. already created, it will create them automatically. Each object has
  65. associated @netfs_path_entry data structure, which contains creation
  66. mode (permissions and type) and length of the name as long as name itself.
  67. @start - 0
  68. @size - size of the all data structures needed to create a path
  69. @id - local inode number
  70. @ext - 0
  71. @NETFS_REMOVE
  72. Used to remove object.
  73. @ext - length of the path to object.
  74. @size - the same.
  75. @id - local inode number.
  76. @start - zero.
  77. @NETFS_LOOKUP
  78. Lookup information about object on server.
  79. @ext - length of the path to object.
  80. @size - the same.
  81. @id - local inode number of the directory to look object in.
  82. @start - local inode number of the object to look at.
  83. @NETFS_LINK
  84. Create hard of symlink.
  85. Command is sent as "object_path|target_path".
  86. @size - size of the above string.
  87. @id - parent local inode number.
  88. @start - 1 for symlink, 0 for hardlink.
  89. @ext - size of the "object_path" above.
  90. @NETFS_TRANS
  91. Transaction header.
  92. @size - incorporates all embedded command sizes including theirs header sizes.
  93. @start - transaction generation number - unique id used to find transaction.
  94. @ext - transaction flags. Unused at the moment.
  95. @id - 0.
  96. @NETFS_OPEN
  97. Open intent for given transaction.
  98. @id - local inode number.
  99. @start - 0.
  100. @size - path length to the object.
  101. @ext - open flags (O_RDWR and so on).
  102. @NETFS_INODE_INFO
  103. Metadata update command.
  104. It is sent to servers when attributes of the object are changed and received
  105. when data or metadata were updated. It operates with the following structure:
  106. struct netfs_inode_info
  107. {
  108. unsigned int mode;
  109. unsigned int nlink;
  110. unsigned int uid;
  111. unsigned int gid;
  112. unsigned int blocksize;
  113. unsigned int padding;
  114. __u64 ino;
  115. __u64 blocks;
  116. __u64 rdev;
  117. __u64 size;
  118. __u64 version;
  119. };
  120. It effectively mirrors stat(2) returned data.
  121. @ext - path length to the object.
  122. @size - the same plus size of the netfs_inode_info structure.
  123. @id - local inode number.
  124. @start - 0.
  125. @NETFS_PAGE_CACHE
  126. Command is only received by clients. It contains information about
  127. page to be marked as not up-to-date.
  128. @id - client's inode number.
  129. @start - last byte of the page to be invalidated. If it is not equal to
  130. current inode size, it will be vmtruncated().
  131. @size - 0
  132. @ext - 0
  133. @NETFS_READ_PAGES
  134. Used to read multiple contiguous pages in one go.
  135. @start - first byte of the contiguous region to read.
  136. @size - contains of two fields: lower 8 bits are used to represent page cache shift
  137. used by client, another 3 bytes are used to get number of pages.
  138. @id - local inode number.
  139. @ext - path length to the object.
  140. @NETFS_RENAME
  141. Used to rename object.
  142. Attached data is formed into following string: "old_path|new_path".
  143. @id - local inode number.
  144. @start - parent inode number.
  145. @size - length of the above string.
  146. @ext - length of the old path part.
  147. @NETFS_CAPABILITIES
  148. Used to exchange crypto capabilities with server.
  149. If crypto capabilities are not supported by server, then client will disable it
  150. or fail (if 'crypto_fail_unsupported' mount options was specified).
  151. @id - superblock index. Used to specify crypto information for group of servers.
  152. @size - size of the attached capabilities structure.
  153. @start - 0.
  154. @size - 0.
  155. @scsize - 0.
  156. @NETFS_LOCK
  157. Used to send lock request/release messages. Although it sends byte range request
  158. and is capable of flushing pages based on that, it is not used, since all Linux
  159. filesystems lock the whole inode.
  160. @id - lock generation number.
  161. @start - start of the locked range.
  162. @size - size of the locked range.
  163. @ext - lock type: read/write. Not used actually. 15'th bit is used to determine,
  164. if it is lock request (1) or release (0).
  165. @NETFS_XATTR_SET
  166. @NETFS_XATTR_GET
  167. Used to set/get extended attributes for given inode.
  168. @id - attribute generation number or xattr setting type
  169. @start - size of the attribute (request or attached)
  170. @size - name length, path len and data size for given attribute
  171. @ext - path length for given object