edit commit description
[ext4-patch-queue.git] / crypto-trace-events
blob3e11ba4b551bb89f5453bab3ae7decaa0a7ad434
1 ext4 crypto: trace events for encrypt and decrypt
3 From: Michael Halcrow <mhalcrow@google.com>
5 Signed-off-by: Michael Halcrow <mhalcrow@google.com>
6 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
7 ---
8  fs/ext4/crypto.c            | 34 ++++++++++++++++++++++++++++++++-
9  include/trace/events/ext4.h | 46 +++++++++++++++++++++++++++++++++++++++++++++
10  2 files changed, 79 insertions(+), 1 deletion(-)
12 diff --git a/fs/ext4/crypto.c b/fs/ext4/crypto.c
13 index e16170f..30cfaa9 100644
14 --- a/fs/ext4/crypto.c
15 +++ b/fs/ext4/crypto.c
16 @@ -31,6 +31,8 @@
17  #include "ext4.h"
18  #include "xattr.h"
20 +#include <trace/events/ext4.h>
22  /* Encryption added and removed here! (L: */
24  mempool_t *ext4_bounce_page_pool = NULL;
25 @@ -447,6 +449,13 @@ struct page *ext4_encrypt(struct ext4_crypto_ctx *ctx,
26                           struct page *plaintext_page)
27  {
28         struct page *ciphertext_page = NULL;
29 +       char c0, c4095, p0, p4095;
30 +       char *page_virt;
32 +       page_virt = kmap(plaintext_page);
33 +       p0 = page_virt[0];
34 +       p4095 = page_virt[PAGE_CACHE_SIZE - 1];
35 +       kunmap(plaintext_page);
37         BUG_ON(!PageLocked(plaintext_page));
38         switch (ctx->mode) {
39 @@ -464,8 +473,16 @@ struct page *ext4_encrypt(struct ext4_crypto_ctx *ctx,
40         default:
41                 BUG();
42         }
43 -       if (!IS_ERR_OR_NULL(ciphertext_page))
44 +       if (!IS_ERR_OR_NULL(ciphertext_page)) {
45                 ext4_prep_pages_for_write(ciphertext_page, plaintext_page, ctx);
47 +               page_virt = kmap(ciphertext_page);
48 +               c0 = page_virt[0];
49 +               c4095 = page_virt[PAGE_CACHE_SIZE - 1];
50 +               kunmap(ciphertext_page);
52 +               trace_ext4_encrypt(plaintext_page, p0, p4095, c0, c4095);
53 +       }
54         return ciphertext_page;
55  }
57 @@ -549,6 +566,13 @@ bool __ext4_debug_is_page_zero(struct page *page)
58  int ext4_decrypt(struct ext4_crypto_ctx *ctx, struct page *page)
59  {
60         int res = 0;
61 +       char c0, c4095, p0, p4095;
62 +       char *page_virt;
64 +       page_virt = kmap(page);
65 +       c0 = page_virt[0];
66 +       c4095 = page_virt[PAGE_CACHE_SIZE - 1];
67 +       kunmap(page);
69         BUG_ON(!PageLocked(page));
70         BUG_ON(__ext4_debug_is_page_zero(page));
71 @@ -564,6 +588,14 @@ int ext4_decrypt(struct ext4_crypto_ctx *ctx, struct page *page)
72         default:
73                 BUG();
74         }
76 +       page_virt = kmap(page);
77 +       p0 = page_virt[0];
78 +       p4095 = page_virt[PAGE_CACHE_SIZE - 1];
79 +       kunmap(page);
81 +       trace_ext4_decrypt(page, p0, p4095, c0, c4095);
83         return res;
84  }
86 diff --git a/include/trace/events/ext4.h b/include/trace/events/ext4.h
87 index d4f70a7..91835b1 100644
88 --- a/include/trace/events/ext4.h
89 +++ b/include/trace/events/ext4.h
90 @@ -494,6 +494,38 @@ DECLARE_EVENT_CLASS(ext4__page_op,
91                   (unsigned long) __entry->index)
92  );
94 +DECLARE_EVENT_CLASS(ext4__page_crypt_op,
95 +       TP_PROTO(struct page *page, char p0, char p4095, char c0, char c4095),
97 +       TP_ARGS(page, p0, p4095, c0, c4095),
99 +       TP_STRUCT__entry(
100 +               __field(        ino_t,  ino                     )
101 +               __field(        pgoff_t, index                  )
102 +               __field(        char,   p0                      )
103 +               __field(        char,   p4095                   )
104 +               __field(        char,   c0                      )
105 +               __field(        char,   c4095                   )
106 +       ),
108 +       TP_fast_assign(
109 +               __entry->ino    = page->mapping->host->i_ino;
110 +               __entry->index  = page->index;
111 +               __entry->p0     = p0;
112 +               __entry->p4095  = p4095;
113 +               __entry->c0     = c0;
114 +               __entry->c4095  = c4095;
115 +       ),
117 +       TP_printk("ino %lu page_index %lu p0 %.2x p4095 %.2x c0 %.2x c4095 %.2x",
118 +                 (unsigned long) __entry->ino,
119 +                 (unsigned long) __entry->index,
120 +                 (unsigned char) __entry->p0,
121 +                 (unsigned char) __entry->p4095,
122 +                 (unsigned char) __entry->c0,
123 +                 (unsigned char) __entry->c4095)
126  DEFINE_EVENT(ext4__page_op, ext4_writepage,
128         TP_PROTO(struct page *page),
129 @@ -515,6 +547,20 @@ DEFINE_EVENT(ext4__page_op, ext4_releasepage,
130         TP_ARGS(page)
131  );
133 +DEFINE_EVENT(ext4__page_crypt_op, ext4_encrypt,
135 +       TP_PROTO(struct page *page, char p0, char p4095, char c0, char c4095),
137 +       TP_ARGS(page, p0, p4095, c0, c4095)
140 +DEFINE_EVENT(ext4__page_crypt_op, ext4_decrypt,
142 +       TP_PROTO(struct page *page, char p0, char p4095, char c0, char c4095),
144 +       TP_ARGS(page, p0, p4095, c0, c4095)
147  DECLARE_EVENT_CLASS(ext4_invalidatepage_op,
148         TP_PROTO(struct page *page, unsigned int offset, unsigned int length),
150 -- 
151 2.1.0.rc2.206.gedb03e5