label.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of version 2 of the GNU General Public License as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. */
  13. #ifndef __LABEL_H__
  14. #define __LABEL_H__
  15. #include <linux/ndctl.h>
  16. #include <linux/sizes.h>
  17. #include <linux/io.h>
  18. enum {
  19. NSINDEX_SIG_LEN = 16,
  20. NSINDEX_ALIGN = 256,
  21. NSINDEX_SEQ_MASK = 0x3,
  22. NSLABEL_UUID_LEN = 16,
  23. NSLABEL_NAME_LEN = 64,
  24. NSLABEL_FLAG_ROLABEL = 0x1, /* read-only label */
  25. NSLABEL_FLAG_LOCAL = 0x2, /* DIMM-local namespace */
  26. NSLABEL_FLAG_BTT = 0x4, /* namespace contains a BTT */
  27. NSLABEL_FLAG_UPDATING = 0x8, /* label being updated */
  28. BTT_ALIGN = 4096, /* all btt structures */
  29. BTTINFO_SIG_LEN = 16,
  30. BTTINFO_UUID_LEN = 16,
  31. BTTINFO_FLAG_ERROR = 0x1, /* error state (read-only) */
  32. BTTINFO_MAJOR_VERSION = 1,
  33. ND_LABEL_MIN_SIZE = 512 * 129, /* see sizeof_namespace_index() */
  34. ND_LABEL_ID_SIZE = 50,
  35. ND_NSINDEX_INIT = 0x1,
  36. };
  37. static const char NSINDEX_SIGNATURE[] = "NAMESPACE_INDEX\0";
  38. /**
  39. * struct nd_namespace_index - label set superblock
  40. * @sig: NAMESPACE_INDEX\0
  41. * @flags: placeholder
  42. * @seq: sequence number for this index
  43. * @myoff: offset of this index in label area
  44. * @mysize: size of this index struct
  45. * @otheroff: offset of other index
  46. * @labeloff: offset of first label slot
  47. * @nslot: total number of label slots
  48. * @major: label area major version
  49. * @minor: label area minor version
  50. * @checksum: fletcher64 of all fields
  51. * @free[0]: bitmap, nlabel bits
  52. *
  53. * The size of free[] is rounded up so the total struct size is a
  54. * multiple of NSINDEX_ALIGN bytes. Any bits this allocates beyond
  55. * nlabel bits must be zero.
  56. */
  57. struct nd_namespace_index {
  58. u8 sig[NSINDEX_SIG_LEN];
  59. __le32 flags;
  60. __le32 seq;
  61. __le64 myoff;
  62. __le64 mysize;
  63. __le64 otheroff;
  64. __le64 labeloff;
  65. __le32 nslot;
  66. __le16 major;
  67. __le16 minor;
  68. __le64 checksum;
  69. u8 free[0];
  70. };
  71. /**
  72. * struct nd_namespace_label - namespace superblock
  73. * @uuid: UUID per RFC 4122
  74. * @name: optional name (NULL-terminated)
  75. * @flags: see NSLABEL_FLAG_*
  76. * @nlabel: num labels to describe this ns
  77. * @position: labels position in set
  78. * @isetcookie: interleave set cookie
  79. * @lbasize: LBA size in bytes or 0 for pmem
  80. * @dpa: DPA of NVM range on this DIMM
  81. * @rawsize: size of namespace
  82. * @slot: slot of this label in label area
  83. * @unused: must be zero
  84. */
  85. struct nd_namespace_label {
  86. u8 uuid[NSLABEL_UUID_LEN];
  87. u8 name[NSLABEL_NAME_LEN];
  88. __le32 flags;
  89. __le16 nlabel;
  90. __le16 position;
  91. __le64 isetcookie;
  92. __le64 lbasize;
  93. __le64 dpa;
  94. __le64 rawsize;
  95. __le32 slot;
  96. __le32 unused;
  97. };
  98. /**
  99. * struct nd_label_id - identifier string for dpa allocation
  100. * @id: "{blk|pmem}-<namespace uuid>"
  101. */
  102. struct nd_label_id {
  103. char id[ND_LABEL_ID_SIZE];
  104. };
  105. /*
  106. * If the 'best' index is invalid, so is the 'next' index. Otherwise,
  107. * the next index is MOD(index+1, 2)
  108. */
  109. static inline int nd_label_next_nsindex(int index)
  110. {
  111. if (index < 0)
  112. return -1;
  113. return (index + 1) % 2;
  114. }
  115. struct nvdimm_drvdata;
  116. int nd_label_validate(struct nvdimm_drvdata *ndd);
  117. void nd_label_copy(struct nvdimm_drvdata *ndd, struct nd_namespace_index *dst,
  118. struct nd_namespace_index *src);
  119. size_t sizeof_namespace_index(struct nvdimm_drvdata *ndd);
  120. int nd_label_active_count(struct nvdimm_drvdata *ndd);
  121. struct nd_namespace_label *nd_label_active(struct nvdimm_drvdata *ndd, int n);
  122. u32 nd_label_alloc_slot(struct nvdimm_drvdata *ndd);
  123. bool nd_label_free_slot(struct nvdimm_drvdata *ndd, u32 slot);
  124. u32 nd_label_nfree(struct nvdimm_drvdata *ndd);
  125. struct nd_region;
  126. struct nd_namespace_pmem;
  127. struct nd_namespace_blk;
  128. int nd_pmem_namespace_label_update(struct nd_region *nd_region,
  129. struct nd_namespace_pmem *nspm, resource_size_t size);
  130. int nd_blk_namespace_label_update(struct nd_region *nd_region,
  131. struct nd_namespace_blk *nsblk, resource_size_t size);
  132. #endif /* __LABEL_H__ */