From: Dave Chinner Date: Mon, 1 Dec 2014 23:32:11 +0000 (+1100) Subject: libxfs: do all xfs->libxfs defines inside libxfs/ X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d2b85cc3af934c26dcb05a89daafe4b142ad2b0;p=thirdparty%2Fxfsprogs-dev.git libxfs: do all xfs->libxfs defines inside libxfs/ Currently include/libxfs does some #define libxfs.... xfs... conversions, allowing external functions to call xfs namespace functions directly. All of the exported functions from libxfs shoul dbe compiled in as libxfs_... namespace symbols, and so such defines should be in libxfs/xfs.h and done the opposite way around. This exposes an awful lot of incorrectly namespaced calls in the userspace code and highlights functions that we weren't expressly exporting from libxfs, so we need to fix them up at the same time. As such, this patchset starts laying the groundwork for a more formalised libxfs interface definition. The libxfs code will need to be restructured to match the kernel code restructing that was done in 3.17, so this interface will become more formalised and defined as that work is done. Signed-off-by: Dave Chinner --- diff --git a/db/metadump.c b/db/metadump.c index 38cd441cb..aba36e051 100644 --- a/db/metadump.c +++ b/db/metadump.c @@ -1816,7 +1816,7 @@ process_inode( } if (crc_was_ok && need_new_crc) - xfs_dinode_calc_crc(mp, dip); + libxfs_dinode_calc_crc(mp, dip); return success; } diff --git a/include/libxfs.h b/include/libxfs.h index 45a924fc9..81fe269b2 100644 --- a/include/libxfs.h +++ b/include/libxfs.h @@ -684,9 +684,126 @@ extern unsigned long libxfs_physmem(void); /* in kilobytes */ #define XFS_INOBT_IS_FREE_DISK(rp,i) \ ((be64_to_cpu((rp)->ir_free) & XFS_INOBT_MASK(i)) != 0) +#define xfs_notice(mp,fmt,args...) cmn_err(CE_NOTE,fmt, ## args) +#define xfs_warn(mp,fmt,args...) cmn_err(CE_WARN,fmt, ## args) +#define xfs_alert(mp,fmt,args...) cmn_err(CE_ALERT,fmt, ## args) +#define xfs_hex_dump(d,n) ((void) 0) + +/* CRC wrappers */ + +extern uint32_t crc32_le(uint32_t crc, unsigned char const *p, size_t len); +extern uint32_t crc32c_le(uint32_t crc, unsigned char const *p, size_t len); + +#define crc32(c,p,l) crc32_le((c),(unsigned char const *)(p),(l)) +#define crc32c(c,p,l) crc32c_le((c),(unsigned char const *)(p),(l)) + +#include + +static inline int +xfs_buf_verify_cksum(struct xfs_buf *bp, unsigned long cksum_offset) +{ + return xfs_verify_cksum(bp->b_addr, BBTOB(bp->b_length), + cksum_offset); +} + +static inline void +xfs_buf_update_cksum(struct xfs_buf *bp, unsigned long cksum_offset) +{ + xfs_update_cksum(bp->b_addr, BBTOB(bp->b_length), + cksum_offset); +} + /* * public xfs kernel routines to be called as libxfs_* + * + * These are all present in the xfs_* namespace but we don't want that namespace + * to be used or even exposed, and hence we declare them here explicitly if we + * aren't directly building the libxfs code itself. + * + * XXX: This needs to be more formalised in the shared header files so that + * these declarations can go away, and so there's documentation in the kernel + * code base that certain functions are shared with userspace. */ +#ifndef __LIBXFS_INTERNAL_XFS_H + +/* xfs_sb.h */ +void libxfs_mod_sb(struct xfs_trans *, __int64_t); +void libxfs_sb_from_disk(struct xfs_sb *, struct xfs_dsb *); +void libxfs_sb_to_disk(struct xfs_dsb *, struct xfs_sb *, __int64_t); +void libxfs_sb_quota_from_disk(struct xfs_sb *sbp); + +/* xfs_bmap.h */ +int libxfs_bmapi_write(struct xfs_trans *tp, struct xfs_inode *ip, + xfs_fileoff_t bno, xfs_filblks_t len, int flags, + xfs_fsblock_t *firstblock, xfs_extlen_t total, + struct xfs_bmbt_irec *mval, int *nmap, + struct xfs_bmap_free *flist); +int libxfs_bunmapi(struct xfs_trans *tp, struct xfs_inode *ip, + xfs_fileoff_t bno, xfs_filblks_t len, int flags, + xfs_extnum_t nexts, xfs_fsblock_t *firstblock, + struct xfs_bmap_free *flist, int *done); +void libxfs_bmap_cancel(struct xfs_bmap_free *flist); +int libxfs_bmap_last_offset(struct xfs_trans *tp, struct xfs_inode *ip, + xfs_fileoff_t *unused, int whichfork); + +/* xfs_dir2.h */ +int libxfs_dir_init(struct xfs_trans *tp, struct xfs_inode *dp, + struct xfs_inode *pdp); +int libxfs_dir_createname(struct xfs_trans *tp, struct xfs_inode *dp, + struct xfs_name *name, xfs_ino_t inum, + xfs_fsblock_t *first, + struct xfs_bmap_free *flist, xfs_extlen_t tot); +int libxfs_dir_lookup(struct xfs_trans *tp, struct xfs_inode *dp, + struct xfs_name *name, xfs_ino_t *inum, + struct xfs_name *ci_name); +int libxfs_dir_replace(struct xfs_trans *tp, struct xfs_inode *dp, + struct xfs_name *name, xfs_ino_t inum, + xfs_fsblock_t *first, + struct xfs_bmap_free *flist, xfs_extlen_t tot); + +int libxfs_dir2_isblock(struct xfs_trans *tp, struct xfs_inode *dp, int *r); +int libxfs_dir2_isleaf(struct xfs_trans *tp, struct xfs_inode *dp, int *r); +int libxfs_dir2_shrink_inode(struct xfs_da_args *args, xfs_dir2_db_t db, + struct xfs_buf *bp); +void libxfs_dir2_data_freescan(struct xfs_mount *mp, + struct xfs_dir2_data_hdr *hdr, int *loghead); +void libxfs_dir2_data_log_entry(struct xfs_trans *tp, struct xfs_buf *bp, + struct xfs_dir2_data_entry *dep); +void libxfs_dir2_data_log_header(struct xfs_trans *tp, + struct xfs_buf *bp); +void libxfs_dir2_data_make_free(struct xfs_trans *tp, struct xfs_buf *bp, + xfs_dir2_data_aoff_t offset, xfs_dir2_data_aoff_t len, + int *needlogp, int *needscanp); +void libxfs_dir2_data_use_free(struct xfs_trans *tp, struct xfs_buf *bp, + struct xfs_dir2_data_unused *dup, xfs_dir2_data_aoff_t offset, + xfs_dir2_data_aoff_t len, int *needlogp, int *needscanp); + +/* xfs_da_btree.h */ +uint libxfs_da_hashname(const __uint8_t *name_string, int name_length); +int libxfs_da_shrink_inode(xfs_da_args_t *args, xfs_dablk_t dead_blkno, + struct xfs_buf *dead_buf); +int libxfs_da_read_buf(struct xfs_trans *trans, struct xfs_inode *dp, + xfs_dablk_t bno, xfs_daddr_t mappedbno, + struct xfs_buf **bpp, int whichfork, + const struct xfs_buf_ops *ops); + + +/* xfs_inode_buf.h */ +void libxfs_dinode_calc_crc(struct xfs_mount *, struct xfs_dinode *); + +/* xfs_inode_fork.h */ +void libxfs_idata_realloc(struct xfs_inode *, int, int); + +/* xfs_shared.h */ +int libxfs_symlink_blocks(struct xfs_mount *mp, int pathlen); +bool libxfs_symlink_hdr_ok(struct xfs_mount *mp, xfs_ino_t ino, + uint32_t offset, uint32_t size, + struct xfs_buf *bp); + +/* xfs_bit.h */ +/* XXX: these are special as they are static inline functions in the header */ +#define libxfs_highbit32 xfs_highbit32 +#define libxfs_highbit64 xfs_highbit64 /* xfs_alloc.c */ int libxfs_alloc_fix_freelist(xfs_alloc_arg_t *, int); @@ -702,103 +819,23 @@ int libxfs_attr_remove(struct xfs_inode *, const unsigned char *, int); xfs_bmbt_rec_host_t *xfs_bmap_search_extents(xfs_inode_t *, xfs_fileoff_t, int, int *, xfs_extnum_t *, xfs_bmbt_irec_t *, xfs_bmbt_irec_t *); -void xfs_bmbt_disk_get_all(xfs_bmbt_rec_t *r, xfs_bmbt_irec_t *s); - -/* xfs_attr_leaf.h */ -#define libxfs_attr_leaf_newentsize xfs_attr_leaf_newentsize +void libxfs_bmbt_disk_get_all(xfs_bmbt_rec_t *r, xfs_bmbt_irec_t *s); -/* xfs_bit.h */ -#define libxfs_highbit32 xfs_highbit32 -#define libxfs_highbit64 xfs_highbit64 - -/* xfs_bmap.h */ -#define libxfs_bmap_cancel xfs_bmap_cancel -#define libxfs_bmap_last_offset xfs_bmap_last_offset -#define libxfs_bmapi_write xfs_bmapi_write -#define libxfs_bmapi_read xfs_bmapi_read -#define libxfs_bunmapi xfs_bunmapi - -/* xfs_bmap_btree.h */ -#define libxfs_bmbt_disk_get_all xfs_bmbt_disk_get_all - -/* xfs_da_btree.h */ -#define libxfs_da_brelse xfs_da_brelse -#define libxfs_da_hashname xfs_da_hashname -#define libxfs_da_shrink_inode xfs_da_shrink_inode -#define libxfs_da_read_buf xfs_da_read_buf - -/* xfs_dir2.h */ -#define libxfs_dir_createname xfs_dir_createname -#define libxfs_dir_init xfs_dir_init -#define libxfs_dir_lookup xfs_dir_lookup -#define libxfs_dir_replace xfs_dir_replace -#define libxfs_dir2_isblock xfs_dir2_isblock -#define libxfs_dir2_isleaf xfs_dir2_isleaf - -/* xfs_dir2_data.h */ -#define libxfs_dir2_data_freescan xfs_dir2_data_freescan -#define libxfs_dir2_data_log_entry xfs_dir2_data_log_entry -#define libxfs_dir2_data_log_header xfs_dir2_data_log_header -#define libxfs_dir2_data_make_free xfs_dir2_data_make_free -#define libxfs_dir2_data_use_free xfs_dir2_data_use_free -#define libxfs_dir2_shrink_inode xfs_dir2_shrink_inode - -/* xfs_inode.h */ -#define libxfs_dinode_from_disk xfs_dinode_from_disk -#define libxfs_dinode_to_disk xfs_dinode_to_disk -void xfs_dinode_from_disk(struct xfs_icdinode *, +void libxfs_dinode_from_disk(struct xfs_icdinode *, struct xfs_dinode *); -#define libxfs_dinode_calc_crc xfs_dinode_calc_crc -#define libxfs_idata_realloc xfs_idata_realloc -#define libxfs_idestroy_fork xfs_idestroy_fork +bool libxfs_dinode_verify(struct xfs_mount *mp, xfs_ino_t ino, + struct xfs_dinode *dip); -#define libxfs_dinode_verify xfs_dinode_verify -bool xfs_dinode_verify(struct xfs_mount *mp, xfs_ino_t ino, - struct xfs_dinode *dip); +/* this file */ +/* XXX: this needs cleanup like the xfs_bit.h stuff */ +#define libxfs_buf_verify_cksum xfs_buf_verify_cksum +#define libxfs_buf_update_cksum xfs_buf_update_cksum -/* xfs_sb.h */ -#define libxfs_mod_sb xfs_mod_sb -#define libxfs_sb_from_disk xfs_sb_from_disk -#define libxfs_sb_quota_from_disk xfs_sb_quota_from_disk -#define libxfs_sb_to_disk xfs_sb_to_disk - -/* xfs_symlink.h */ -#define libxfs_symlink_blocks xfs_symlink_blocks -#define libxfs_symlink_hdr_ok xfs_symlink_hdr_ok - -/* xfs_trans_resv.h */ -#define libxfs_trans_resv_calc xfs_trans_resv_calc +#endif /* __LIBXFS_INTERNAL_XFS_H */ +/* XXX: this is clearly a bug - a shared header needs to export this */ /* xfs_rtalloc.c */ int libxfs_rtfree_extent(struct xfs_trans *, xfs_rtblock_t, xfs_extlen_t); -/* CRC wrappers */ - -extern uint32_t crc32_le(uint32_t crc, unsigned char const *p, size_t len); -extern uint32_t crc32c_le(uint32_t crc, unsigned char const *p, size_t len); - -#define crc32(c,p,l) crc32_le((c),(unsigned char const *)(p),(l)) -#define crc32c(c,p,l) crc32c_le((c),(unsigned char const *)(p),(l)) - -#include - -static inline int -xfs_buf_verify_cksum(struct xfs_buf *bp, unsigned long cksum_offset) -{ - return xfs_verify_cksum(bp->b_addr, BBTOB(bp->b_length), - cksum_offset); -} - -static inline void -xfs_buf_update_cksum(struct xfs_buf *bp, unsigned long cksum_offset) -{ - xfs_update_cksum(bp->b_addr, BBTOB(bp->b_length), - cksum_offset); -} - -#define xfs_notice(mp,fmt,args...) cmn_err(CE_NOTE,fmt, ## args) -#define xfs_warn(mp,fmt,args...) cmn_err(CE_WARN,fmt, ## args) -#define xfs_alert(mp,fmt,args...) cmn_err(CE_ALERT,fmt, ## args) -#define xfs_hex_dump(d,n) ((void) 0) #endif /* __LIBXFS_H__ */ diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c index 7d7347769..2fe4bcde6 100644 --- a/libxfs/rdwr.c +++ b/libxfs/rdwr.c @@ -16,7 +16,7 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include +#include "xfs.h" #include "init.h" /* diff --git a/libxfs/xfs.h b/libxfs/xfs.h index 30a316d32..8865a8a2c 100644 --- a/libxfs/xfs.h +++ b/libxfs/xfs.h @@ -42,6 +42,124 @@ * specifically there to support the user level build. */ +/* + * define a guard and something we can check to determine what include context + * we are running from. + */ +#ifndef __LIBXFS_INTERNAL_XFS_H +#define __LIBXFS_INTERNAL_XFS_H + +/* + * start by remapping all the symbols we expect external users to call + * to the libxfs_ namespace. This ensures that all internal symbols are + * remapped correctly throughout all the included header files + * as well as in the C code. + */ +#define xfs_alloc_fix_freelist libxfs_alloc_fix_freelist +#define xfs_attr_get libxfs_attr_get +#define xfs_attr_set libxfs_attr_set +#define xfs_attr_remove libxfs_attr_remove +#define xfs_rtfree_extent libxfs_rtfree_extent + +#define xfs_fs_repair_cmn_err libxfs_fs_repair_cmn_err +#define xfs_fs_cmn_err libxfs_fs_cmn_err + +#define xfs_bmap_finish libxfs_bmap_finish +#define xfs_trans_ichgtime libxfs_trans_ichgtime +#define xfs_mod_incore_sb libxfs_mod_incore_sb + +#define xfs_trans_alloc libxfs_trans_alloc +#define xfs_trans_add_item libxfs_trans_add_item +#define xfs_trans_bhold libxfs_trans_bhold +#define xfs_trans_binval libxfs_trans_binval +#define xfs_trans_bjoin libxfs_trans_bjoin +#define xfs_trans_brelse libxfs_trans_brelse +#define xfs_trans_commit libxfs_trans_commit +#define xfs_trans_cancel libxfs_trans_cancel +#define xfs_trans_del_item libxfs_trans_del_item +#define xfs_trans_dup libxfs_trans_dup +#define xfs_trans_get_buf libxfs_trans_get_buf +#define xfs_trans_getsb libxfs_trans_getsb +#define xfs_trans_iget libxfs_trans_iget +#define xfs_trans_ijoin libxfs_trans_ijoin +#define xfs_trans_ijoin_ref libxfs_trans_ijoin_ref +#define xfs_trans_init libxfs_trans_init +#define xfs_trans_inode_alloc_buf libxfs_trans_inode_alloc_buf +#define xfs_trans_log_buf libxfs_trans_log_buf +#define xfs_trans_log_inode libxfs_trans_log_inode +#define xfs_trans_mod_sb libxfs_trans_mod_sb +#define xfs_trans_read_buf libxfs_trans_read_buf +#define xfs_trans_read_buf_map libxfs_trans_read_buf_map +#define xfs_trans_roll libxfs_trans_roll +#define xfs_trans_get_buf_map libxfs_trans_get_buf_map +#define xfs_trans_reserve libxfs_trans_reserve + +/* xfs_attr_leaf.h */ +#define xfs_attr_leaf_newentsize libxfs_attr_leaf_newentsize + +/* xfs_bit.h */ +#define xfs_highbit32 libxfs_highbit32 +#define xfs_highbit64 libxfs_highbit64 + +/* xfs_bmap.h */ +#define xfs_bmap_cancel libxfs_bmap_cancel +#define xfs_bmap_last_offset libxfs_bmap_last_offset +#define xfs_bmapi_write libxfs_bmapi_write +#define xfs_bmapi_read libxfs_bmapi_read +#define xfs_bunmapi libxfs_bunmapi + +/* xfs_bmap_btree.h */ +#define xfs_bmbt_disk_get_all libxfs_bmbt_disk_get_all + +/* xfs_da_btree.h */ +#define xfs_da_brelse libxfs_da_brelse +#define xfs_da_hashname libxfs_da_hashname +#define xfs_da_shrink_inode libxfs_da_shrink_inode +#define xfs_da_read_buf libxfs_da_read_buf + +/* xfs_dir2.h */ +#define xfs_dir_createname libxfs_dir_createname +#define xfs_dir_init libxfs_dir_init +#define xfs_dir_lookup libxfs_dir_lookup +#define xfs_dir_replace libxfs_dir_replace +#define xfs_dir2_isblock libxfs_dir2_isblock +#define xfs_dir2_isleaf libxfs_dir2_isleaf + +/* xfs_dir2_data.h */ +#define xfs_dir2_data_freescan libxfs_dir2_data_freescan +#define xfs_dir2_data_log_entry libxfs_dir2_data_log_entry +#define xfs_dir2_data_log_header libxfs_dir2_data_log_header +#define xfs_dir2_data_make_free libxfs_dir2_data_make_free +#define xfs_dir2_data_use_free libxfs_dir2_data_use_free +#define xfs_dir2_shrink_inode libxfs_dir2_shrink_inode + +/* xfs_inode.h */ +#define xfs_dinode_from_disk libxfs_dinode_from_disk +#define xfs_dinode_to_disk libxfs_dinode_to_disk +#define xfs_dinode_calc_crc libxfs_dinode_calc_crc +#define xfs_idata_realloc libxfs_idata_realloc +#define xfs_idestroy_fork libxfs_idestroy_fork + +#define xfs_dinode_verify libxfs_dinode_verify + +/* xfs_sb.h */ +#define xfs_mod_sb libxfs_mod_sb +#define xfs_sb_from_disk libxfs_sb_from_disk +#define xfs_sb_quota_from_disk libxfs_sb_quota_from_disk +#define xfs_sb_to_disk libxfs_sb_to_disk + +/* xfs_symlink.h */ +#define xfs_symlink_blocks libxfs_symlink_blocks +#define xfs_symlink_hdr_ok libxfs_symlink_hdr_ok + +/* xfs_trans_resv.h */ +#define xfs_trans_resv_calc libxfs_trans_resv_calc + + +/* + * Now we've renamed and mapped everything, include the rest of the external + * libxfs headers. + */ #include #include "xfs_dir2_priv.h" @@ -262,48 +380,6 @@ roundup_64(__uint64_t x, __uint32_t y) #define xfs_icsb_modify_counters(mp, field, delta, rsvd) \ xfs_mod_incore_sb(mp, field, delta, rsvd) -/* - * Map XFS kernel routine names to libxfs versions - */ - -#define xfs_alloc_fix_freelist libxfs_alloc_fix_freelist -#define xfs_attr_get libxfs_attr_get -#define xfs_attr_set libxfs_attr_set -#define xfs_attr_remove libxfs_attr_remove -#define xfs_rtfree_extent libxfs_rtfree_extent - -#define xfs_fs_repair_cmn_err libxfs_fs_repair_cmn_err -#define xfs_fs_cmn_err libxfs_fs_cmn_err - -#define xfs_bmap_finish libxfs_bmap_finish -#define xfs_trans_ichgtime libxfs_trans_ichgtime -#define xfs_mod_incore_sb libxfs_mod_incore_sb - -#define xfs_trans_alloc libxfs_trans_alloc -#define xfs_trans_add_item libxfs_trans_add_item -#define xfs_trans_bhold libxfs_trans_bhold -#define xfs_trans_binval libxfs_trans_binval -#define xfs_trans_bjoin libxfs_trans_bjoin -#define xfs_trans_brelse libxfs_trans_brelse -#define xfs_trans_commit libxfs_trans_commit -#define xfs_trans_cancel libxfs_trans_cancel -#define xfs_trans_del_item libxfs_trans_del_item -#define xfs_trans_dup libxfs_trans_dup -#define xfs_trans_get_buf libxfs_trans_get_buf -#define xfs_trans_getsb libxfs_trans_getsb -#define xfs_trans_iget libxfs_trans_iget -#define xfs_trans_ijoin libxfs_trans_ijoin -#define xfs_trans_ijoin_ref libxfs_trans_ijoin_ref -#define xfs_trans_init libxfs_trans_init -#define xfs_trans_inode_alloc_buf libxfs_trans_inode_alloc_buf -#define xfs_trans_log_buf libxfs_trans_log_buf -#define xfs_trans_log_inode libxfs_trans_log_inode -#define xfs_trans_mod_sb libxfs_trans_mod_sb -#define xfs_trans_read_buf libxfs_trans_read_buf -#define xfs_trans_read_buf_map libxfs_trans_read_buf_map -#define xfs_trans_roll libxfs_trans_roll -#define xfs_trans_get_buf_map libxfs_trans_get_buf_map -#define xfs_trans_reserve libxfs_trans_reserve #define xfs_trans_get_block_res(tp) 1 #define xfs_trans_set_sync(tp) ((void) 0) @@ -449,3 +525,5 @@ void xfs_trans_mod_sb(xfs_trans_t *, uint, long); void xfs_trans_init(struct xfs_mount *); int xfs_trans_roll(struct xfs_trans **, struct xfs_inode *); void xfs_verifier_error(struct xfs_buf *bp); + +#endif /* __LIBXFS_INTERNAL_XFS_H */ diff --git a/mkfs/proto.c b/mkfs/proto.c index 72068f024..744dcc6c6 100644 --- a/mkfs/proto.c +++ b/mkfs/proto.c @@ -241,7 +241,7 @@ newfile( flags = 0; mp = ip->i_mount; if (dolocal && len <= XFS_IFORK_DSIZE(ip)) { - xfs_idata_realloc(ip, len, XFS_DATA_FORK); + libxfs_idata_realloc(ip, len, XFS_DATA_FORK); if (buf) memmove(ip->i_df.if_u1.if_data, buf, len); ip->i_d.di_size = len;