nfs_page.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * linux/include/linux/nfs_page.h
  3. *
  4. * Copyright (C) 2000 Trond Myklebust
  5. *
  6. * NFS page cache wrapper.
  7. */
  8. #ifndef _LINUX_NFS_PAGE_H
  9. #define _LINUX_NFS_PAGE_H
  10. #include <linux/list.h>
  11. #include <linux/pagemap.h>
  12. #include <linux/wait.h>
  13. #include <linux/nfs_fs_sb.h>
  14. #include <linux/sunrpc/auth.h>
  15. #include <linux/nfs_xdr.h>
  16. #include <asm/atomic.h>
  17. /*
  18. * Valid flags for a dirty buffer
  19. */
  20. #define PG_BUSY 0
  21. #define PG_NEED_COMMIT 1
  22. #define PG_NEED_RESCHED 2
  23. struct nfs_page {
  24. struct list_head wb_list, /* Defines state of page: */
  25. *wb_list_head; /* read/write/commit */
  26. struct page *wb_page; /* page to read in/write out */
  27. struct nfs_open_context *wb_context; /* File state context info */
  28. atomic_t wb_complete; /* i/os we're waiting for */
  29. unsigned long wb_index; /* Offset >> PAGE_CACHE_SHIFT */
  30. unsigned int wb_offset, /* Offset & ~PAGE_CACHE_MASK */
  31. wb_pgbase, /* Start of page data */
  32. wb_bytes; /* Length of request */
  33. atomic_t wb_count; /* reference count */
  34. unsigned long wb_flags;
  35. struct nfs_writeverf wb_verf; /* Commit cookie */
  36. };
  37. #define NFS_WBACK_BUSY(req) (test_bit(PG_BUSY,&(req)->wb_flags))
  38. #define NFS_NEED_COMMIT(req) (test_bit(PG_NEED_COMMIT,&(req)->wb_flags))
  39. #define NFS_NEED_RESCHED(req) (test_bit(PG_NEED_RESCHED,&(req)->wb_flags))
  40. extern struct nfs_page *nfs_create_request(struct nfs_open_context *ctx,
  41. struct inode *inode,
  42. struct page *page,
  43. unsigned int offset,
  44. unsigned int count);
  45. extern void nfs_clear_request(struct nfs_page *req);
  46. extern void nfs_release_request(struct nfs_page *req);
  47. extern void nfs_list_add_request(struct nfs_page *, struct list_head *);
  48. extern int nfs_scan_list(struct list_head *, struct list_head *,
  49. unsigned long, unsigned int);
  50. extern int nfs_coalesce_requests(struct list_head *, struct list_head *,
  51. unsigned int);
  52. extern int nfs_wait_on_request(struct nfs_page *);
  53. extern void nfs_unlock_request(struct nfs_page *req);
  54. /*
  55. * Lock the page of an asynchronous request without incrementing the wb_count
  56. */
  57. static inline int
  58. nfs_lock_request_dontget(struct nfs_page *req)
  59. {
  60. if (test_and_set_bit(PG_BUSY, &req->wb_flags))
  61. return 0;
  62. return 1;
  63. }
  64. /*
  65. * Lock the page of an asynchronous request
  66. */
  67. static inline int
  68. nfs_lock_request(struct nfs_page *req)
  69. {
  70. if (test_and_set_bit(PG_BUSY, &req->wb_flags))
  71. return 0;
  72. atomic_inc(&req->wb_count);
  73. return 1;
  74. }
  75. /**
  76. * nfs_list_remove_request - Remove a request from its wb_list
  77. * @req: request
  78. */
  79. static inline void
  80. nfs_list_remove_request(struct nfs_page *req)
  81. {
  82. if (list_empty(&req->wb_list))
  83. return;
  84. if (!NFS_WBACK_BUSY(req)) {
  85. printk(KERN_ERR "NFS: unlocked request attempted removed from list!\n");
  86. BUG();
  87. }
  88. list_del_init(&req->wb_list);
  89. req->wb_list_head = NULL;
  90. }
  91. static inline int
  92. nfs_defer_commit(struct nfs_page *req)
  93. {
  94. if (test_and_set_bit(PG_NEED_COMMIT, &req->wb_flags))
  95. return 0;
  96. return 1;
  97. }
  98. static inline void
  99. nfs_clear_commit(struct nfs_page *req)
  100. {
  101. smp_mb__before_clear_bit();
  102. clear_bit(PG_NEED_COMMIT, &req->wb_flags);
  103. smp_mb__after_clear_bit();
  104. }
  105. static inline int
  106. nfs_defer_reschedule(struct nfs_page *req)
  107. {
  108. if (test_and_set_bit(PG_NEED_RESCHED, &req->wb_flags))
  109. return 0;
  110. return 1;
  111. }
  112. static inline void
  113. nfs_clear_reschedule(struct nfs_page *req)
  114. {
  115. smp_mb__before_clear_bit();
  116. clear_bit(PG_NEED_RESCHED, &req->wb_flags);
  117. smp_mb__after_clear_bit();
  118. }
  119. static inline struct nfs_page *
  120. nfs_list_entry(struct list_head *head)
  121. {
  122. return list_entry(head, struct nfs_page, wb_list);
  123. }
  124. static inline
  125. loff_t req_offset(struct nfs_page *req)
  126. {
  127. return (((loff_t)req->wb_index) << PAGE_CACHE_SHIFT) + req->wb_offset;
  128. }
  129. #endif /* _LINUX_NFS_PAGE_H */