xlog_rec_header/xlog_rec_ext_header endianess annotations
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 5 lines · Christoph Hellwig
Mostly trivial conversion with one exceptions:
h_num_logopswas kept in native endian previously and only converted to big endian inxlog_sync, but we always keep it big endian now. With todays cpus fast byteswap instructions that's not an issue but the new variant keeps the code clean and maintainable.
Here's an updated patch to apply ontop of Eric's spinlock changes.
Btw, did this series get through to anyone? I didn't recieve it back from the list and the archives don't seem to have it either..
fs/xfs/xfs_log.c +42 -48
@@ -1227,12 +1227,12 @@ xlog_alloc_log(xfs_mount_t *mp, head = &iclog->ic_header;memset (head,0 ,sizeof (xlog_rec_header_t)); -INT_SET (head->h_magicno,ARCH_CONVERT ,XLOG_HEADER_MAGIC_NUM ); -INT_SET (head->h_version,ARCH_CONVERT , + head->h_magicno =cpu_to_be32 (XLOG_HEADER_MAGIC_NUM ); + head->h_version =cpu_to_be32 (XFS_SB_VERSION_HASLOGV2 (&log->l_mp->m_sb) ?2 :1 ); -INT_SET (head->h_size,ARCH_CONVERT , log->l_iclog_size); + head->h_size =cpu_to_be32 (log->l_iclog_size);/* new fields */ -INT_SET (head->h_fmt,ARCH_CONVERT ,XLOG_FMT ); + head->h_fmt =cpu_to_be32 (XLOG_FMT );memcpy (&head->h_fs_uuid, &mp->m_sb.sb_uuid,sizeof (uuid_t));
@@ -1378,7 +1378,7 @@ xlog_sync(xlog_t *log, {xfs_caddr_t dptr;/* pointer to byte sized element */ xfs_buf_t *bp; -int i, ops; +int i;uint count;/* byte count of bwrite */ uint count_init;/* initial count before roundup */ int roundoff;/* roundoff to BB or stripe */
@@ -1417,21 +1417,17 @@ xlog_sync(xlog_t *log,/* real byte length */ if (v2) { -INT_SET (iclog->ic_header.h_len, -ARCH_CONVERT , - iclog->ic_offset + roundoff); + iclog->ic_header.h_len = +cpu_to_be32 (iclog->ic_offset + roundoff); }else { -INT_SET (iclog->ic_header.h_len,ARCH_CONVERT , iclog->ic_offset); + iclog->ic_header.h_len = +cpu_to_be32 (iclog->ic_offset); } -/* put ops count in correct order */ - ops = iclog->ic_header.h_num_logops; -INT_SET (iclog->ic_header.h_num_logops,ARCH_CONVERT , ops); - bp = iclog->ic_bp; ASSERT(XFS_BUF_FSPRIVATE2(bp, unsigned long) == (unsigned long)1);XFS_BUF_SET_FSPRIVATE2 (bp, (unsigned long )2 ); -XFS_BUF_SET_ADDR (bp,BLOCK_LSN (INT_GET (iclog->ic_header.h_lsn,ARCH_CONVERT ))); +XFS_BUF_SET_ADDR (bp,BLOCK_LSN (be64_to_cpu (iclog->ic_header.h_lsn)));XFS_STATS_ADD (xs_log_blocks,BTOBB (count));
@@ -1494,10 +1490,10 @@ xlog_sync(xlog_t *log,* a new cycle. Watch out for the header magic number * case, though. */ -for (i=0 ; i<split; i +=BBSIZE ) { -INT_MOD (*(uint *)dptr,ARCH_CONVERT ,+1 ); -if (INT_GET (*(uint *)dptr,ARCH_CONVERT ) ==XLOG_HEADER_MAGIC_NUM ) -INT_MOD (*(uint *)dptr,ARCH_CONVERT ,+1 ); +for (i =0 ; i < split; i +=BBSIZE ) { +be32_add ((__be32 *)dptr,1 ); +if (be32_to_cpu (*(__be32 *)dptr) ==XLOG_HEADER_MAGIC_NUM ) +be32_add ((__be32 *)dptr,1 ); dptr +=BBSIZE ; }
@@ -1586,7 +1582,7 @@ xlog_state_finish_copy(xlog_t *log, {spin_lock (&log->l_icloglock); - iclog->ic_header.h_num_logops += record_cnt; +be32_add (&iclog->ic_header.h_num_logops, record_cnt); iclog->ic_offset += copy_bytes;spin_unlock (&log->l_icloglock);
@@ -1813,7 +1809,7 @@ xlog_write(xfs_mount_t * mp,/* start_lsn is the first lsn written to. That's all we need. */ if (! *start_lsn) - *start_lsn =INT_GET (iclog->ic_header.h_lsn,ARCH_CONVERT ); + *start_lsn =be64_to_cpu (iclog->ic_header.h_lsn);/* This loop writes out as many regions as can fit in the amount * of space which was allocated by xlog_state_get_iclog_space().
@@ -1983,7 +1979,8 @@ xlog_state_clean_log(xlog_t *log)* We don't need to cover the dummy. */ if (!changed && - (INT_GET (iclog->ic_header.h_num_logops,ARCH_CONVERT ) ==XLOG_COVER_OPS )) { + (be32_to_cpu (iclog->ic_header.h_num_logops) == +XLOG_COVER_OPS )) { changed =1 ; }else {/*
@@ -2051,7 +2048,7 @@ xlog_get_lowest_lsn( lowest_lsn =0 ; do { if (!(lsn_log->ic_state & (XLOG_STATE_ACTIVE|XLOG_STATE_DIRTY))) { - lsn = INT_GET(lsn_log->ic_header.h_lsn, ARCH_CONVERT); + lsn = be64_to_cpu(lsn_log->ic_header.h_lsn); if ((lsn && !lowest_lsn) || (XFS_LSN_CMP(lsn, lowest_lsn) < 0)) { lowest_lsn = lsn;
@@ -2152,11 +2149,9 @@ xlog_state_do_callback(*/ lowest_lsn =xlog_get_lowest_lsn (log); -if (lowest_lsn && ( -XFS_LSN_CMP ( - lowest_lsn, -INT_GET (iclog->ic_header.h_lsn,ARCH_CONVERT ) - )<0 )) { +if (lowest_lsn && +XFS_LSN_CMP (lowest_lsn, +be64_to_cpu (iclog->ic_header.h_lsn)) <0 ) { iclog = iclog->ic_next;continue ;/* Leave this iclog for * another thread */
@@ -2171,11 +2166,10 @@ xlog_state_do_callback(* No one else can be here except us. */ spin_lock (&log->l_grant_lock); -ASSERT (XFS_LSN_CMP ( - log->l_last_sync_lsn, -INT_GET (iclog->ic_header.h_lsn,ARCH_CONVERT ) - )<=0 ); - log->l_last_sync_lsn =INT_GET (iclog->ic_header.h_lsn,ARCH_CONVERT ); +ASSERT (XFS_LSN_CMP (log->l_last_sync_lsn, +be64_to_cpu (iclog->ic_header.h_lsn)) <=0 ); + log->l_last_sync_lsn = +be64_to_cpu (iclog->ic_header.h_lsn);spin_unlock (&log->l_grant_lock);/*
@@ -2392,8 +2386,8 @@ restart:xlog_tic_add_region (ticket, log->l_iclog_hsize,XLOG_REG_TYPE_LRHEADER ); -INT_SET (head->h_cycle,ARCH_CONVERT , log->l_curr_cycle); -INT_SET (head->h_lsn,ARCH_CONVERT , + head->h_cycle =cpu_to_be32 (log->l_curr_cycle); + head->h_lsn =cpu_to_be64 (xlog_assign_lsn (log->l_curr_cycle, log->l_curr_block));ASSERT (log->l_curr_block >=0 ); }
@@ -2823,7 +2817,7 @@ xlog_state_release_iclog(xlog_t *log, iclog->ic_state == XLOG_STATE_WANT_SYNC) { sync++; iclog->ic_state =XLOG_STATE_SYNCING ; -INT_SET (iclog->ic_header.h_tail_lsn,ARCH_CONVERT , log->l_tail_lsn); + iclog->ic_header.h_tail_lsn =cpu_to_be64 (log->l_tail_lsn);xlog_verify_tail_lsn (log, iclog, log->l_tail_lsn);/* cycle incremented when incrementing curr_block */ }
@@ -2861,7 +2855,7 @@ xlog_state_switch_iclogs(xlog_t *log,if (!eventual_size) eventual_size = iclog->ic_offset; iclog->ic_state =XLOG_STATE_WANT_SYNC ; -INT_SET (iclog->ic_header.h_prev_block,ARCH_CONVERT , log->l_prev_block); + iclog->ic_header.h_prev_block =cpu_to_be32 (log->l_prev_block); log->l_prev_block = log->l_curr_block; log->l_prev_cycle = log->l_curr_cycle;
@@ -2957,7 +2951,7 @@ xlog_state_sync_all(xlog_t *log, uint fl* the previous sync. */ iclog->ic_refcnt++; - lsn =INT_GET (iclog->ic_header.h_lsn,ARCH_CONVERT ); + lsn =be64_to_cpu (iclog->ic_header.h_lsn);xlog_state_switch_iclogs (log, iclog,0 );spin_unlock (&log->l_icloglock);
@@ -2965,7 +2959,7 @@ xlog_state_sync_all(xlog_t *log, uint flreturn XFS_ERROR (EIO ); *log_flushed =1 ;spin_lock (&log->l_icloglock); -if (INT_GET (iclog->ic_header.h_lsn,ARCH_CONVERT ) == lsn && +if (be64_to_cpu (iclog->ic_header.h_lsn) == lsn && iclog->ic_state !=XLOG_STATE_DIRTY ) goto maybe_sleep;else
@@ -3049,9 +3043,9 @@ try_again: } do { - if (INT_GET(iclog->ic_header.h_lsn, ARCH_CONVERT) != lsn) { - iclog = iclog->ic_next; - continue; + if (be64_to_cpu(iclog->ic_header.h_lsn) != lsn) { + iclog = iclog->ic_next; + continue; } if (iclog->ic_state == XLOG_STATE_DIRTY) {
@@ -3460,18 +3454,18 @@ xlog_verify_iclog(xlog_t *log,spin_unlock (&log->l_icloglock);/* check log magic numbers */ - ptr = (xfs_caddr_t) &(iclog->ic_header); -if (INT_GET (*(uint *)ptr,ARCH_CONVERT ) !=XLOG_HEADER_MAGIC_NUM ) +if (be32_to_cpu (iclog->ic_header.h_magicno) !=XLOG_HEADER_MAGIC_NUM )xlog_panic ("xlog_verify_iclog: invalid magic num" ); -for (ptr +=BBSIZE ; ptr < ((xfs_caddr_t)&(iclog->ic_header))+count; + ptr = (xfs_caddr_t) &iclog->ic_header; +for (ptr +=BBSIZE ; ptr < ((xfs_caddr_t)&iclog->ic_header) + count; ptr +=BBSIZE ) { -if (INT_GET (*(uint *)ptr,ARCH_CONVERT ) ==XLOG_HEADER_MAGIC_NUM ) +if (be32_to_cpu (*(__be32 *)ptr) ==XLOG_HEADER_MAGIC_NUM )xlog_panic ("xlog_verify_iclog: unexpected magic num" ); }/* check fields */ - len =INT_GET (iclog->ic_header.h_num_logops,ARCH_CONVERT ); + len =be32_to_cpu (iclog->ic_header.h_num_logops); ptr = iclog->ic_datap; base_ptr = ptr; ophead = (xlog_op_header_t *)ptr;
@@ -3512,9 +3506,9 @@ xlog_verify_iclog(xlog_t *log,if (idx >= (XLOG_HEADER_CYCLE_SIZE /BBSIZE )) { j = idx / (XLOG_HEADER_CYCLE_SIZE /BBSIZE ); k = idx % (XLOG_HEADER_CYCLE_SIZE /BBSIZE ); - op_len =INT_GET (xhdr[j].hic_xheader.xh_cycle_data[k],ARCH_CONVERT ); + op_len =be32_to_cpu (xhdr[j].hic_xheader.xh_cycle_data[k]); }else { - op_len =INT_GET (iclog->ic_header.h_cycle_data[idx],ARCH_CONVERT ); + op_len =be32_to_cpu (iclog->ic_header.h_cycle_data[idx]); } } ptr +=sizeof (xlog_op_header_t) + op_len;
fs/xfs/xfs_log_priv.h +20 -20
@@ -63,10 +63,10 @@ static inline xfs_lsn_t xlog_assign_lsn(static inline uint xlog_get_cycle (char *ptr) { -if (INT_GET (*(uint *)ptr,ARCH_CONVERT ) ==XLOG_HEADER_MAGIC_NUM ) -return INT_GET (*((uint *)ptr +1 ),ARCH_CONVERT ); +if (be32_to_cpu (*(__be32 *)ptr) ==XLOG_HEADER_MAGIC_NUM ) +return be32_to_cpu (*((__be32 *)ptr +1 ));else -return INT_GET (*(uint *)ptr,ARCH_CONVERT ); +return be32_to_cpu (*(__be32 *)ptr); }#define BLK_AVG (blk1, blk2) ((blk1+blk2) >> 1)
@@ -85,9 +85,9 @@ static inline uint xlog_get_cycle(char ** * this has endian issues, of course. */ -static inline uint xlog_get_client_id (uint i) +static inline uint xlog_get_client_id (__be32 i) { -return INT_GET (i,ARCH_CONVERT ) >>24 ; +return be32_to_cpu (i) >>24 ; } #define xlog_panic(args...) cmn_err(CE_PANIC, ## args)
@@ -287,25 +287,25 @@ typedef struct xlog_op_header {#endif typedef struct xlog_rec_header { -uint h_magicno;/* log record (LR) identifier : 4 */ -uint h_cycle;/* write cycle of log : 4 */ -int h_version;/* LR version : 4 */ -int h_len;/* len in bytes; should be 64-bit aligned: 4 */ -xfs_lsn_t h_lsn;/* lsn of this LR : 8 */ -xfs_lsn_t h_tail_lsn;/* lsn of 1st LR w/ buffers not committed: 8 */ -uint h_chksum;/* may not be used; non-zero if used : 4 */ -int h_prev_block;/* block number to previous LR : 4 */ -int h_num_logops;/* number of log operations in this LR : 4 */ -uint h_cycle_data[XLOG_HEADER_CYCLE_SIZE /BBSIZE ]; +__be32 h_magicno;/* log record (LR) identifier : 4 */ +__be32 h_cycle;/* write cycle of log : 4 */ +__be32 h_version;/* LR version : 4 */ +__be32 h_len;/* len in bytes; should be 64-bit aligned: 4 */ +__be64 h_lsn;/* lsn of this LR : 8 */ +__be64 h_tail_lsn;/* lsn of 1st LR w/ buffers not committed: 8 */ +__be32 h_chksum;/* may not be used; non-zero if used : 4 */ +__be32 h_prev_block;/* block number to previous LR : 4 */ +__be32 h_num_logops;/* number of log operations in this LR : 4 */ +__be32 h_cycle_data[XLOG_HEADER_CYCLE_SIZE /BBSIZE ];/* new fields */ -int h_fmt;/* format of log record : 4 */ -uuid_t h_fs_uuid;/* uuid of FS : 16 */ -int h_size;/* iclog size : 4 */ +__be32 h_fmt;/* format of log record : 4 */ +uuid_t h_fs_uuid;/* uuid of FS : 16 */ +__be32 h_size;/* iclog size : 4 */ }xlog_rec_header_t ;typedef struct xlog_rec_ext_header { -uint xh_cycle;/* write cycle of log : 4 */ -uint xh_cycle_data[XLOG_HEADER_CYCLE_SIZE /BBSIZE ];/* : 256 */ +__be32 xh_cycle;/* write cycle of log : 4 */ +__be32 xh_cycle_data[XLOG_HEADER_CYCLE_SIZE /BBSIZE ];/* : 256 */ }xlog_rec_ext_header_t ;#ifdef __KERNEL__
fs/xfs/xfs_log_recover.c +56 -64
334 lines not on this page · raw message
fs/xfs/xfsidbg.c +10 -6
@@ -5739,17 +5739,21 @@ xfsidbg_xiclog(xlog_in_core_t *iclog)kdb_printf ("xlog_in_core/header at 0x%p/0x%p\n" , iclog, iclog->hic_data);kdb_printf ("magicno: %x cycle: %d version: %d lsn: 0x%Lx\n" , -INT_GET (iclog->ic_header.h_magicno,ARCH_CONVERT ),INT_GET (iclog->ic_header.h_cycle,ARCH_CONVERT ), -INT_GET (iclog->ic_header.h_version,ARCH_CONVERT ),INT_GET (iclog->ic_header.h_lsn,ARCH_CONVERT )); +be32_to_cpu (iclog->ic_header.h_magicno), +be32_to_cpu (iclog->ic_header.h_cycle), +be32_to_cpu (iclog->ic_header.h_version), +be64_to_cpu (iclog->ic_header.h_lsn));kdb_printf ("tail_lsn: 0x%Lx len: %d prev_block: %d num_ops: %d\n" , -INT_GET (iclog->ic_header.h_tail_lsn,ARCH_CONVERT ),INT_GET (iclog->ic_header.h_len,ARCH_CONVERT ), -INT_GET (iclog->ic_header.h_prev_block,ARCH_CONVERT ),INT_GET (iclog->ic_header.h_num_logops,ARCH_CONVERT )); +be64_to_cpu (iclog->ic_header.h_tail_lsn), +be32_to_cpu (iclog->ic_header.h_len), +be32_to_cpu (iclog->ic_header.h_prev_block), +be32_to_cpu (iclog->ic_header.h_num_logops));kdb_printf ("cycle_data: " );for (i=0 ; i<(iclog->ic_size>>BBSHIFT ); i++) { -kdb_printf ("%x " ,INT_GET (iclog->ic_header.h_cycle_data[i],ARCH_CONVERT )); +kdb_printf ("%x " ,be32_to_cpu (iclog->ic_header.h_cycle_data[i])); }kdb_printf ("\n" ); -kdb_printf ("size: %d\n" ,INT_GET (iclog->ic_header.h_size,ARCH_CONVERT )); +kdb_printf ("size: %d\n" ,be32_to_cpu (iclog->ic_header.h_size));kdb_printf ("\n" );kdb_printf ("--------------------------------------------------\n" ); kdb_printf("data: 0x%p &forcesema: 0x%p next: 0x%p bp: 0x%p\n",
fs/xfs/xfs_log.h +2 -1
@@ -22,8 +22,9 @@#define CYCLE_LSN (lsn) ((uint)((lsn)>>32))#define BLOCK_LSN (lsn) ((uint)(lsn)) +/* this is used in a spot where we might otherwise double-endian-flip */ -#define CYCLE_LSN_DISK (lsn) (((uint *)&(lsn))[0]) +#define CYCLE_LSN_DISK (lsn) (((__be32 *)&(lsn))[0])#ifdef __KERNEL__/*