@@ -20,6 +20,7 @@
#ifndef __LINUX_BVEC_ITER_H
#define __LINUX_BVEC_ITER_H
+#include <asm/bitsperlong.h>
#include <linux/kernel.h>
#include <linux/bug.h>
#include <linux/errno.h>
@@ -34,6 +35,9 @@ struct bio_vec {
unsigned int bv_offset;
};
+#define BVEC_PFN_GUP (1UL << (BITS_PER_LONG - 1))
+#define BVEC_PFN_MASK (~BVEC_PFN_GUP)
+
struct bvec_iter {
sector_t bi_sector; /* device address in 512 byte
sectors */
@@ -58,7 +62,13 @@ static inline unsigned long page_to_bvec_pfn(struct page *page)
static inline struct page *bvec_page(const struct bio_vec *bvec)
{
- return bvec->bv_pfn == -1UL ? NULL : pfn_to_page(bvec->bv_pfn);
+ return bvec->bv_pfn == -1UL ? NULL :
+ pfn_to_page(bvec->bv_pfn & BVEC_PFN_MASK);
+}
+
+static inline void bvec_set_gup_page(struct bio_vec *bvec, struct page *page)
+{
+ bvec->bv_pfn = page_to_bvec_pfn(page) | BVEC_PFN_GUP;
}
static inline void bvec_set_page(struct bio_vec *bvec, struct page *page)
@@ -71,6 +81,46 @@ static inline struct page *bvec_nth_page(struct page *page, int idx)
return idx == 0 ? page : nth_page(page, idx);
}
+static inline void bvec_put_page(const struct bio_vec *bvec)
+{
+ struct page *page = bvec_page(bvec);
+
+ if (page == NULL)
+ return;
+
+ if (bvec->bv_pfn & BVEC_PFN_GUP)
+ put_user_page(page);
+ else
+ put_page(page);
+}
+
+static inline void bvec_put_page_dirty(const struct bio_vec *bvec, bool dirty)
+{
+ struct page *page = bvec_page(bvec);
+
+ if (page == NULL)
+ return;
+
+ if (dirty)
+ set_page_dirty(page);
+
+ bvec_put_page(bvec);
+}
+
+static inline void bvec_put_page_dirty_lock(const struct bio_vec *bvec,
+ bool dirty)
+{
+ struct page *page = bvec_page(bvec);
+
+ if (page == NULL)
+ return;
+
+ if (dirty)
+ set_page_dirty_lock(page);
+
+ bvec_put_page(bvec);
+}
+
/*
* various member access, note that bio_data should of course not be used
* on highmem page vectors