CDEBUG(D_INFO, "%s: new reply_data file, initializing\n",
tgt_name(tgt));
lrh->lrh_magic = LRH_MAGIC;
- lrh->lrh_header_size = sizeof(struct lsd_reply_header);
- lrh->lrh_reply_size = sizeof(struct lsd_reply_data);
+ lrh->lrh_header_size = sizeof(*lrh);
+ lrh->lrh_reply_size = sizeof(*lrd);
rc = tgt_reply_header_write(env, tgt, lrh);
if (rc) {
CERROR("%s: error writing %s: rc = %d\n",
GOTO(out, rc);
}
} else {
- __u32 recsz = sizeof(struct lsd_reply_data);
+ __u32 recsz = sizeof(*lrd);
+ const char *lrd_ver = "v2";
rc = tgt_reply_header_read(env, tgt, lrh);
if (rc) {
tgt_name(tgt), REPLY_DATA, rc);
GOTO(out, rc);
}
- if (!(lrh->lrh_magic == LRH_MAGIC &&
- lrh->lrh_reply_size == sizeof(struct lsd_reply_data) &&
- lrh->lrh_header_size == sizeof(struct lsd_reply_header)) &&
- !(lrh->lrh_magic == LRH_MAGIC_V1 &&
- lrh->lrh_reply_size == sizeof(struct lsd_reply_data_v1) &&
- lrh->lrh_header_size == sizeof(struct lsd_reply_header))) {
- CERROR("%s: invalid header in %s\n",
- tgt_name(tgt), REPLY_DATA);
- GOTO(out, rc = -EINVAL);
- }
- if (lrh->lrh_magic == LRH_MAGIC_V1)
+ switch (lrh->lrh_magic) {
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 5, 53, 0)
+ /* The old reply_data is replaced on the first mount after
+ * an upgrade, so no need to keep this interop code forever.
+ */
+ case LRH_MAGIC_V1:
recsz = sizeof(struct lsd_reply_data_v1);
+ lrd_ver = "v1";
+
+ CWARN("%s: %s v1 will be upgraded to new record size\n",
+ tgt_name(tgt), REPLY_DATA);
+ fallthrough;
+#endif
+ case LRH_MAGIC_V2:
+ if (lrh->lrh_header_size != sizeof(*lrh)) {
+ CERROR("%s: bad %s %s header size: %u != %lu\n",
+ tgt_name(tgt), REPLY_DATA, lrd_ver,
+ lrh->lrh_header_size, sizeof(*lrh));
+ GOTO(out, rc = -EINVAL);
+ }
+ if (lrh->lrh_reply_size != recsz) {
+ CERROR("%s: bad %s %s reply size: %u != %u\n",
+ tgt_name(tgt), REPLY_DATA, lrd_ver,
+ lrh->lrh_reply_size, recsz);
+ GOTO(out, rc = -EINVAL);
+ }
+ break;
+ default:
+ CERROR("%s: invalid %s magic: %x != %x/%x\n",
+ tgt_name(tgt), REPLY_DATA,
+ lrh->lrh_magic, LRH_MAGIC_V1, LRH_MAGIC_V2);
+ GOTO(out, rc = -EINVAL);
+ }
hash = cfs_hash_getref(tgt->lut_obd->obd_gen_hash);
if (hash == NULL)
GOTO(out, rc = -ENOMEM);
/* Load reply_data from disk */
- for (idx = 0, off = sizeof(struct lsd_reply_header);
+ for (idx = 0, off = lrh->lrh_header_size;
off < reply_data_size; idx++, off += recsz) {
rc = tgt_reply_data_read(env, tgt, lrd, off,
lrh->lrh_magic);