static struct crm_remote_header_v0 * crm_remote_header(crm_remote_t * remote) { struct crm_remote_header_v0 *header = (struct crm_remote_header_v0 *)remote->buffer; if(remote->buffer_offset < sizeof(struct crm_remote_header_v0)) { return NULL; } else if(header->endian != ENDIAN_LOCAL) { uint32_t endian = __swab32(header->endian); CRM_LOG_ASSERT(endian == ENDIAN_LOCAL); if(endian != ENDIAN_LOCAL) { crm_err("Invalid message detected, endian mismatch: %lx is neither %lx nor the swab'd %lx", ENDIAN_LOCAL, header->endian, endian); return NULL; } header->id = __swab64(header->id); header->flags = __swab64(header->flags); header->endian = __swab32(header->endian); header->version = __swab32(header->version); header->size_total = __swab32(header->size_total); header->payload_offset = __swab32(header->payload_offset); header->payload_compressed = __swab32(header->payload_compressed); header->payload_uncompressed = __swab32(header->payload_uncompressed); } return header; }
void ate_write(pcibr_soft_t pcibr_soft, bridge_ate_p ate_ptr, int ate_count, bridge_ate_t ate) { if (IS_PIC_SOFT(pcibr_soft) ) { while (ate_count-- > 0) { *ate_ptr++ = ate; ate += IOPGSIZE; } } else { if (io_get_sh_swapper(NASID_GET(ate_ptr))) { while (ate_count-- > 0) { *ate_ptr++ = __swab64(ate); ate += IOPGSIZE; } } else { while (ate_count-- > 0) { *ate_ptr++ = ate; ate += IOPGSIZE; } } } }
static inline void swap_digits(u64 *in, u64 *out, unsigned int ndigits) { int i; for (i = 0; i < ndigits; i++) out[i] = __swab64(in[ndigits - 1 - i]); }
void cf_buf_builder_append_uint64(cf_buf_builder **bb_r, uint64_t i) { BB_RESERVE(8); cf_buf_builder *bb = *bb_r; uint64_t *i_p = (uint64_t *)&bb->buf[bb->used_sz]; *i_p = __swab64(i); bb->used_sz += 8; }
/* include/linux/byteorder does not support "unsigned long" type */ static inline unsigned long ext2_swab(const unsigned long y) { #if BITS_PER_LONG == 64 return (unsigned long) __swab64((u64) y); #elif BITS_PER_LONG == 32 return (unsigned long) __swab32((u32) y); #else #error BITS_PER_LONG not defined #endif }
int linkea_init(struct linkea_data *ldata) { struct link_ea_header *leh; LASSERT(ldata->ld_buf); leh = ldata->ld_buf->lb_buf; if (leh->leh_magic == __swab32(LINK_EA_MAGIC)) { leh->leh_magic = LINK_EA_MAGIC; leh->leh_reccount = __swab32(leh->leh_reccount); leh->leh_len = __swab64(leh->leh_len); /* entries are swabbed by linkea_entry_unpack */ } if (leh->leh_magic != LINK_EA_MAGIC) return -EINVAL; if (leh->leh_reccount == 0) return -ENODATA; ldata->ld_leh = leh; return 0; }
int linkea_init(struct linkea_data *ldata) { struct link_ea_header *leh; LASSERT(ldata->ld_buf != NULL); leh = ldata->ld_buf->lb_buf; if (leh->leh_magic == __swab32(LINK_EA_MAGIC)) { leh->leh_magic = LINK_EA_MAGIC; leh->leh_reccount = __swab32(leh->leh_reccount); leh->leh_len = __swab64(leh->leh_len); leh->leh_overflow_time = __swab32(leh->leh_overflow_time); leh->leh_padding = __swab32(leh->leh_padding); /* individual entries are swabbed by linkea_entry_unpack() */ } if (leh->leh_magic != LINK_EA_MAGIC) return -EINVAL; if (leh->leh_reccount == 0 && leh->leh_overflow_time == 0) return -ENODATA; ldata->ld_leh = leh; return 0; }
/* * Determine the size of this bridge's external mapping SSRAM, and set * the control register appropriately to reflect this size, and initialize * the external SSRAM. */ int pcibr_init_ext_ate_ram(bridge_t *bridge) { int largest_working_size = 0; int num_entries, entry; int i, j; bridgereg_t old_enable, new_enable; int s; int this_is_pic = is_pic(bridge); /* Probe SSRAM to determine its size. */ if ( this_is_pic ) { old_enable = bridge->b_int_enable; new_enable = old_enable & ~BRIDGE_IMR_PCI_MST_TIMEOUT; bridge->b_int_enable = new_enable; } else { if (io_get_sh_swapper(NASID_GET(bridge))) { old_enable = BRIDGE_REG_GET32((&bridge->b_int_enable)); new_enable = old_enable & ~BRIDGE_IMR_PCI_MST_TIMEOUT; BRIDGE_REG_SET32((&bridge->b_int_enable)) = new_enable; } else { old_enable = bridge->b_int_enable; new_enable = old_enable & ~BRIDGE_IMR_PCI_MST_TIMEOUT; bridge->b_int_enable = new_enable; } } for (i = 1; i < ATE_NUM_SIZES; i++) { /* Try writing a value */ if ( this_is_pic ) { bridge->b_ext_ate_ram[ATE_NUM_ENTRIES(i) - 1] = ATE_PROBE_VALUE; } else { if (io_get_sh_swapper(NASID_GET(bridge))) bridge->b_ext_ate_ram[ATE_NUM_ENTRIES(i) - 1] = __swab64(ATE_PROBE_VALUE); else bridge->b_ext_ate_ram[ATE_NUM_ENTRIES(i) - 1] = ATE_PROBE_VALUE; } /* Guard against wrap */ for (j = 1; j < i; j++) bridge->b_ext_ate_ram[ATE_NUM_ENTRIES(j) - 1] = 0; /* See if value was written */ if ( this_is_pic ) { if (bridge->b_ext_ate_ram[ATE_NUM_ENTRIES(i) - 1] == ATE_PROBE_VALUE) largest_working_size = i; } else { if (io_get_sh_swapper(NASID_GET(bridge))) { if (bridge->b_ext_ate_ram[ATE_NUM_ENTRIES(i) - 1] == __swab64(ATE_PROBE_VALUE)) largest_working_size = i; else { if (bridge->b_ext_ate_ram[ATE_NUM_ENTRIES(i) - 1] == ATE_PROBE_VALUE) largest_working_size = i; } } } } if ( this_is_pic ) { bridge->b_int_enable = old_enable; bridge->b_wid_tflush; /* wait until Bridge PIO complete */ } else { if (io_get_sh_swapper(NASID_GET(bridge))) { BRIDGE_REG_SET32((&bridge->b_int_enable)) = old_enable; BRIDGE_REG_GET32((&bridge->b_wid_tflush)); /* wait until Bridge PIO complete */ } else { bridge->b_int_enable = old_enable; bridge->b_wid_tflush; /* wait until Bridge PIO complete */ } } /* * ensure that we write and read without any interruption. * The read following the write is required for the Bridge war */ s = splhi(); if ( this_is_pic ) { bridge->b_wid_control = (bridge->b_wid_control & ~BRIDGE_CTRL_SSRAM_SIZE_MASK) | BRIDGE_CTRL_SSRAM_SIZE(largest_working_size); bridge->b_wid_control; /* inval addr bug war */ } else { if (io_get_sh_swapper(NASID_GET(bridge))) { BRIDGE_REG_SET32((&(bridge->b_wid_control))) = __swab32((BRIDGE_REG_GET32((&bridge->b_wid_control)) & ~BRIDGE_CTRL_SSRAM_SIZE_MASK) | BRIDGE_CTRL_SSRAM_SIZE(largest_working_size)); BRIDGE_REG_GET32((&bridge->b_wid_control));/* inval addr bug war */ } else { bridge->b_wid_control = (bridge->b_wid_control & ~BRIDGE_CTRL_SSRAM_SIZE_MASK) | BRIDGE_CTRL_SSRAM_SIZE(largest_working_size); bridge->b_wid_control; /* inval addr bug war */ } } splx(s); num_entries = ATE_NUM_ENTRIES(largest_working_size); if (pcibr_debug_mask & PCIBR_DEBUG_ATE) { if (num_entries) { PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_ATE, NULL, "bridge at 0x%x: clearing %d external ATEs\n", bridge, num_entries)); } else { PCIBR_DEBUG_ALWAYS((PCIBR_DEBUG_ATE, NULL, "bridge at 0x%x: no external ATE RAM found\n", bridge)); } } /* Initialize external mapping entries */ for (entry = 0; entry < num_entries; entry++) bridge->b_ext_ate_ram[entry] = 0; return (num_entries); }
static int osd_find_parent_fid(const struct lu_env *env, struct dt_object *o, struct lu_fid *fid) { struct link_ea_header *leh; struct link_ea_entry *lee; struct lu_buf buf; int rc; ENTRY; buf.lb_buf = osd_oti_get(env)->oti_buf; buf.lb_len = sizeof(osd_oti_get(env)->oti_buf); rc = osd_xattr_get(env, o, &buf, XATTR_NAME_LINK, BYPASS_CAPA); if (rc == -ERANGE) { rc = osd_xattr_get(env, o, &LU_BUF_NULL, XATTR_NAME_LINK, BYPASS_CAPA); if (rc < 0) RETURN(rc); LASSERT(rc > 0); OBD_ALLOC(buf.lb_buf, rc); if (buf.lb_buf == NULL) RETURN(-ENOMEM); buf.lb_len = rc; rc = osd_xattr_get(env, o, &buf, XATTR_NAME_LINK, BYPASS_CAPA); } if (rc < 0) GOTO(out, rc); if (rc < sizeof(*leh) + sizeof(*lee)) GOTO(out, rc = -EINVAL); leh = buf.lb_buf; if (leh->leh_magic == __swab32(LINK_EA_MAGIC)) { leh->leh_magic = LINK_EA_MAGIC; leh->leh_reccount = __swab32(leh->leh_reccount); leh->leh_len = __swab64(leh->leh_len); } if (leh->leh_magic != LINK_EA_MAGIC) GOTO(out, rc = -EINVAL); if (leh->leh_reccount == 0) GOTO(out, rc = -ENODATA); lee = (struct link_ea_entry *)(leh + 1); fid_be_to_cpu(fid, (const struct lu_fid *)&lee->lee_parent_fid); rc = 0; out: if (buf.lb_buf != osd_oti_get(env)->oti_buf) OBD_FREE(buf.lb_buf, buf.lb_len); #if 0 /* this block can be enabled for additional verification * it's trying to match FID from LinkEA vs. FID from LMA */ if (rc == 0) { struct lu_fid fid2; int rc2; rc2 = osd_find_parent_by_dnode(env, o, &fid2); if (rc2 == 0) if (lu_fid_eq(fid, &fid2) == 0) CERROR("wrong parent: "DFID" != "DFID"\n", PFID(fid), PFID(&fid2)); } #endif /* no LinkEA is found, let's try to find the fid in parent's LMA */ if (unlikely(rc != 0)) rc = osd_find_parent_by_dnode(env, o, fid); RETURN(rc); }
int decode_linkea(const char *fname) { char buf[BUFFER_SIZE]; struct link_ea_header *leh; ssize_t size; struct link_ea_entry *lee; int i; __u64 length; int reclen; struct lu_fid pfid; size = getxattr(fname, "trusted.link", buf, BUFFER_SIZE); if (size < 0) { if (errno == ERANGE) { fprintf(stderr, "%s: failed to read trusted.link " "xattr, the buffer size %u might be too " "small\n", fname, BUFFER_SIZE); } else { fprintf(stderr, "%s: failed to read trusted.link xattr: %s\n", fname, strerror(errno)); } return -1; } leh = (struct link_ea_header *)buf; if (leh->leh_magic == __swab32(LINK_EA_MAGIC)) { leh->leh_magic = LINK_EA_MAGIC; leh->leh_reccount = __swab32(leh->leh_reccount); leh->leh_len = __swab64(leh->leh_len); } if (leh->leh_magic != LINK_EA_MAGIC) { fprintf(stderr, "%s: magic mismatch, expected 0x%lx, got 0x%x\n", fname, LINK_EA_MAGIC, leh->leh_magic); return -1; } if (leh->leh_reccount == 0) { fprintf(stderr, "%s: empty record count\n", fname); return -1; } if (leh->leh_len > size) { fprintf(stderr, "%s: invalid length %llu, should smaller than %zd\n", fname, leh->leh_len, size); return -1; } length = sizeof(struct link_ea_header); lee = (struct link_ea_entry *)(leh + 1); printf("%s: count %u\n", fname, leh->leh_reccount); for (i = 0; i < leh->leh_reccount; i++) { reclen = (lee->lee_reclen[0] << 8) | lee->lee_reclen[1]; length += reclen; if (length > leh->leh_len) { fprintf(stderr, "%s: length exceeded, expected %lld, got %lld\n", fname, leh->leh_len, length); return -1; } memcpy(&pfid, &lee->lee_parent_fid, sizeof(pfid)); fid_be_to_cpu(&pfid, &pfid); printf(" %d: pfid "DFID", name '%s'\n", i, PFID(&pfid), lee->lee_name); lee = (struct link_ea_entry *)((char *)lee + reclen); } if (length != leh->leh_len) { fprintf(stderr, "%s: length mismatch, expected %lld, got %lld\n", fname, leh->leh_len, length); return -1; } return 0; }