11da177e4SLinus Torvalds /* 27b718769SNathan Scott * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc. 37b718769SNathan Scott * All Rights Reserved. 41da177e4SLinus Torvalds * 57b718769SNathan Scott * This program is free software; you can redistribute it and/or 67b718769SNathan Scott * modify it under the terms of the GNU General Public License as 71da177e4SLinus Torvalds * published by the Free Software Foundation. 81da177e4SLinus Torvalds * 97b718769SNathan Scott * This program is distributed in the hope that it would be useful, 107b718769SNathan Scott * but WITHOUT ANY WARRANTY; without even the implied warranty of 117b718769SNathan Scott * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 127b718769SNathan Scott * GNU General Public License for more details. 131da177e4SLinus Torvalds * 147b718769SNathan Scott * You should have received a copy of the GNU General Public License 157b718769SNathan Scott * along with this program; if not, write the Free Software Foundation, 167b718769SNathan Scott * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 171da177e4SLinus Torvalds */ 181da177e4SLinus Torvalds #ifndef __XFS_LOG_H__ 191da177e4SLinus Torvalds #define __XFS_LOG_H__ 201da177e4SLinus Torvalds 211da177e4SLinus Torvalds /* get lsn fields */ 221da177e4SLinus Torvalds 231da177e4SLinus Torvalds #define CYCLE_LSN(lsn) ((uint)((lsn)>>32)) 241da177e4SLinus Torvalds #define BLOCK_LSN(lsn) ((uint)(lsn)) 25b53e675dSChristoph Hellwig 261da177e4SLinus Torvalds /* this is used in a spot where we might otherwise double-endian-flip */ 27b53e675dSChristoph Hellwig #define CYCLE_LSN_DISK(lsn) (((__be32 *)&(lsn))[0]) 281da177e4SLinus Torvalds 291da177e4SLinus Torvalds #ifdef __KERNEL__ 301da177e4SLinus Torvalds /* 31c41564b5SNathan Scott * By comparing each component, we don't have to worry about extra 321da177e4SLinus Torvalds * endian issues in treating two 32 bit numbers as one 64 bit number 331da177e4SLinus Torvalds */ 34a1365647SAndrew Morton static inline xfs_lsn_t _lsn_cmp(xfs_lsn_t lsn1, xfs_lsn_t lsn2) 351da177e4SLinus Torvalds { 361da177e4SLinus Torvalds if (CYCLE_LSN(lsn1) != CYCLE_LSN(lsn2)) 371da177e4SLinus Torvalds return (CYCLE_LSN(lsn1)<CYCLE_LSN(lsn2))? -999 : 999; 381da177e4SLinus Torvalds 391da177e4SLinus Torvalds if (BLOCK_LSN(lsn1) != BLOCK_LSN(lsn2)) 401da177e4SLinus Torvalds return (BLOCK_LSN(lsn1)<BLOCK_LSN(lsn2))? -999 : 999; 411da177e4SLinus Torvalds 421da177e4SLinus Torvalds return 0; 431da177e4SLinus Torvalds } 441da177e4SLinus Torvalds 451da177e4SLinus Torvalds #define XFS_LSN_CMP(x,y) _lsn_cmp(x,y) 461da177e4SLinus Torvalds 471da177e4SLinus Torvalds /* 481da177e4SLinus Torvalds * Macros, structures, prototypes for interface to the log manager. 491da177e4SLinus Torvalds */ 501da177e4SLinus Torvalds 511da177e4SLinus Torvalds /* 521da177e4SLinus Torvalds * Flags to xfs_log_done() 531da177e4SLinus Torvalds */ 541da177e4SLinus Torvalds #define XFS_LOG_REL_PERM_RESERV 0x1 551da177e4SLinus Torvalds 561da177e4SLinus Torvalds /* 571da177e4SLinus Torvalds * Flags to xfs_log_reserve() 581da177e4SLinus Torvalds * 591da177e4SLinus Torvalds * XFS_LOG_SLEEP: If space is not available, sleep (default) 601da177e4SLinus Torvalds * XFS_LOG_NOSLEEP: If space is not available, return error 611da177e4SLinus Torvalds * XFS_LOG_PERM_RESERV: Permanent reservation. When writes are 621da177e4SLinus Torvalds * performed against this type of reservation, the reservation 631da177e4SLinus Torvalds * is not decreased. Long running transactions should use this. 641da177e4SLinus Torvalds */ 651da177e4SLinus Torvalds #define XFS_LOG_SLEEP 0x0 661da177e4SLinus Torvalds #define XFS_LOG_NOSLEEP 0x1 671da177e4SLinus Torvalds #define XFS_LOG_PERM_RESERV 0x2 681da177e4SLinus Torvalds 691da177e4SLinus Torvalds /* 701da177e4SLinus Torvalds * Flags to xfs_log_force() 711da177e4SLinus Torvalds * 721da177e4SLinus Torvalds * XFS_LOG_SYNC: Synchronous force in-core log to disk 731da177e4SLinus Torvalds */ 741da177e4SLinus Torvalds #define XFS_LOG_SYNC 0x1 751da177e4SLinus Torvalds 761da177e4SLinus Torvalds #endif /* __KERNEL__ */ 771da177e4SLinus Torvalds 781da177e4SLinus Torvalds 791da177e4SLinus Torvalds /* Log Clients */ 801da177e4SLinus Torvalds #define XFS_TRANSACTION 0x69 811da177e4SLinus Torvalds #define XFS_VOLUME 0x2 821da177e4SLinus Torvalds #define XFS_LOG 0xaa 831da177e4SLinus Torvalds 847e9c6396STim Shimmin 857e9c6396STim Shimmin /* Region types for iovec's i_type */ 867e9c6396STim Shimmin #define XLOG_REG_TYPE_BFORMAT 1 877e9c6396STim Shimmin #define XLOG_REG_TYPE_BCHUNK 2 887e9c6396STim Shimmin #define XLOG_REG_TYPE_EFI_FORMAT 3 897e9c6396STim Shimmin #define XLOG_REG_TYPE_EFD_FORMAT 4 907e9c6396STim Shimmin #define XLOG_REG_TYPE_IFORMAT 5 917e9c6396STim Shimmin #define XLOG_REG_TYPE_ICORE 6 927e9c6396STim Shimmin #define XLOG_REG_TYPE_IEXT 7 937e9c6396STim Shimmin #define XLOG_REG_TYPE_IBROOT 8 947e9c6396STim Shimmin #define XLOG_REG_TYPE_ILOCAL 9 957e9c6396STim Shimmin #define XLOG_REG_TYPE_IATTR_EXT 10 967e9c6396STim Shimmin #define XLOG_REG_TYPE_IATTR_BROOT 11 977e9c6396STim Shimmin #define XLOG_REG_TYPE_IATTR_LOCAL 12 987e9c6396STim Shimmin #define XLOG_REG_TYPE_QFORMAT 13 997e9c6396STim Shimmin #define XLOG_REG_TYPE_DQUOT 14 1007e9c6396STim Shimmin #define XLOG_REG_TYPE_QUOTAOFF 15 1017e9c6396STim Shimmin #define XLOG_REG_TYPE_LRHEADER 16 1027e9c6396STim Shimmin #define XLOG_REG_TYPE_UNMOUNT 17 1037e9c6396STim Shimmin #define XLOG_REG_TYPE_COMMIT 18 1047e9c6396STim Shimmin #define XLOG_REG_TYPE_TRANSHDR 19 1057e9c6396STim Shimmin #define XLOG_REG_TYPE_MAX 19 1067e9c6396STim Shimmin 1071da177e4SLinus Torvalds typedef struct xfs_log_iovec { 1081da177e4SLinus Torvalds xfs_caddr_t i_addr; /* beginning address of region */ 1091da177e4SLinus Torvalds int i_len; /* length in bytes of region */ 1107e9c6396STim Shimmin uint i_type; /* type of region */ 1111da177e4SLinus Torvalds } xfs_log_iovec_t; 1121da177e4SLinus Torvalds 113*55b66332SDave Chinner struct xfs_log_vec { 114*55b66332SDave Chinner struct xfs_log_vec *lv_next; /* next lv in build list */ 115*55b66332SDave Chinner int lv_niovecs; /* number of iovecs in lv */ 116*55b66332SDave Chinner struct xfs_log_iovec *lv_iovecp; /* iovec array */ 117*55b66332SDave Chinner }; 118*55b66332SDave Chinner 1191da177e4SLinus Torvalds /* 1201da177e4SLinus Torvalds * Structure used to pass callback function and the function's argument 1211da177e4SLinus Torvalds * to the log manager. 1221da177e4SLinus Torvalds */ 1231da177e4SLinus Torvalds typedef struct xfs_log_callback { 1241da177e4SLinus Torvalds struct xfs_log_callback *cb_next; 1251da177e4SLinus Torvalds void (*cb_func)(void *, int); 1261da177e4SLinus Torvalds void *cb_arg; 1271da177e4SLinus Torvalds } xfs_log_callback_t; 1281da177e4SLinus Torvalds 1291da177e4SLinus Torvalds 1301da177e4SLinus Torvalds #ifdef __KERNEL__ 1311da177e4SLinus Torvalds /* Log manager interfaces */ 1321da177e4SLinus Torvalds struct xfs_mount; 13335a8a72fSChristoph Hellwig struct xlog_in_core; 134cc09c0dcSDave Chinner struct xlog_ticket; 13543f5efc5SDave Chinner struct xfs_log_item; 13643f5efc5SDave Chinner struct xfs_item_ops; 13743f5efc5SDave Chinner 13843f5efc5SDave Chinner void xfs_log_item_init(struct xfs_mount *mp, 13943f5efc5SDave Chinner struct xfs_log_item *item, 14043f5efc5SDave Chinner int type, 14143f5efc5SDave Chinner struct xfs_item_ops *ops); 14235a8a72fSChristoph Hellwig 1431da177e4SLinus Torvalds xfs_lsn_t xfs_log_done(struct xfs_mount *mp, 14435a8a72fSChristoph Hellwig struct xlog_ticket *ticket, 14535a8a72fSChristoph Hellwig struct xlog_in_core **iclog, 1461da177e4SLinus Torvalds uint flags); 147f538d4daSChristoph Hellwig int _xfs_log_force(struct xfs_mount *mp, 148f538d4daSChristoph Hellwig uint flags, 149f538d4daSChristoph Hellwig int *log_forced); 150b911ca04SDavid Chinner void xfs_log_force(struct xfs_mount *mp, 151a14a348bSChristoph Hellwig uint flags); 152a14a348bSChristoph Hellwig int _xfs_log_force_lsn(struct xfs_mount *mp, 153a14a348bSChristoph Hellwig xfs_lsn_t lsn, 154a14a348bSChristoph Hellwig uint flags, 155a14a348bSChristoph Hellwig int *log_forced); 156a14a348bSChristoph Hellwig void xfs_log_force_lsn(struct xfs_mount *mp, 157b911ca04SDavid Chinner xfs_lsn_t lsn, 158b911ca04SDavid Chinner uint flags); 1591da177e4SLinus Torvalds int xfs_log_mount(struct xfs_mount *mp, 1601da177e4SLinus Torvalds struct xfs_buftarg *log_target, 1611da177e4SLinus Torvalds xfs_daddr_t start_block, 1621da177e4SLinus Torvalds int num_bblocks); 1634249023aSChristoph Hellwig int xfs_log_mount_finish(struct xfs_mount *mp); 1641da177e4SLinus Torvalds void xfs_log_move_tail(struct xfs_mount *mp, 1651da177e4SLinus Torvalds xfs_lsn_t tail_lsn); 1661da177e4SLinus Torvalds int xfs_log_notify(struct xfs_mount *mp, 16735a8a72fSChristoph Hellwig struct xlog_in_core *iclog, 1681da177e4SLinus Torvalds xfs_log_callback_t *callback_entry); 1691da177e4SLinus Torvalds int xfs_log_release_iclog(struct xfs_mount *mp, 17035a8a72fSChristoph Hellwig struct xlog_in_core *iclog); 1711da177e4SLinus Torvalds int xfs_log_reserve(struct xfs_mount *mp, 1721da177e4SLinus Torvalds int length, 1731da177e4SLinus Torvalds int count, 17435a8a72fSChristoph Hellwig struct xlog_ticket **ticket, 1751da177e4SLinus Torvalds __uint8_t clientid, 1767e9c6396STim Shimmin uint flags, 1777e9c6396STim Shimmin uint t_type); 1781da177e4SLinus Torvalds int xfs_log_write(struct xfs_mount *mp, 1791da177e4SLinus Torvalds xfs_log_iovec_t region[], 1801da177e4SLinus Torvalds int nentries, 18135a8a72fSChristoph Hellwig struct xlog_ticket *ticket, 1821da177e4SLinus Torvalds xfs_lsn_t *start_lsn); 1831da177e4SLinus Torvalds int xfs_log_unmount_write(struct xfs_mount *mp); 18421b699c8SChristoph Hellwig void xfs_log_unmount(struct xfs_mount *mp); 1851da177e4SLinus Torvalds int xfs_log_force_umount(struct xfs_mount *mp, int logerror); 1861da177e4SLinus Torvalds int xfs_log_need_covered(struct xfs_mount *mp); 1871da177e4SLinus Torvalds 1881da177e4SLinus Torvalds void xlog_iodone(struct xfs_buf *); 1891da177e4SLinus Torvalds 190cc09c0dcSDave Chinner struct xlog_ticket * xfs_log_ticket_get(struct xlog_ticket *ticket); 191cc09c0dcSDave Chinner void xfs_log_ticket_put(struct xlog_ticket *ticket); 192cc09c0dcSDave Chinner 1931da177e4SLinus Torvalds #endif 1941da177e4SLinus Torvalds 1951da177e4SLinus Torvalds 1961da177e4SLinus Torvalds extern int xlog_debug; /* set to 1 to enable real log */ 1971da177e4SLinus Torvalds 1981da177e4SLinus Torvalds 1991da177e4SLinus Torvalds #endif /* __XFS_LOG_H__ */ 200