[RFC PATCH 37/61] cachefiles: Add I/O tracepoints

From: David Howells
Date: Mon May 04 2020 - 13:13:21 EST



---

fs/cachefiles/interface.c | 16 +++--
fs/cachefiles/io.c | 2 +
include/trace/events/cachefiles.h | 123 +++++++++++++++++++++++++++++++++++++
3 files changed, 136 insertions(+), 5 deletions(-)

diff --git a/fs/cachefiles/interface.c b/fs/cachefiles/interface.c
index aa063857272a..feff39dff0f5 100644
--- a/fs/cachefiles/interface.c
+++ b/fs/cachefiles/interface.c
@@ -160,7 +160,8 @@ static void cachefiles_update_object(struct fscache_object *_object)
struct cachefiles_object *object;
struct cachefiles_cache *cache;
const struct cred *saved_cred;
- loff_t object_size;
+ struct inode *inode;
+ loff_t object_size, i_size;
int ret;

_enter("{OBJ%x}", _object->debug_id);
@@ -172,12 +173,15 @@ static void cachefiles_update_object(struct fscache_object *_object)
cachefiles_begin_secure(cache, &saved_cred);

object_size = object->fscache.cookie->object_size;
- if (i_size_read(d_inode(object->dentry)) > object_size) {
+ inode = d_inode(object->dentry);
+ i_size = i_size_read(inode);
+ if (i_size > object_size) {
struct path path = {
.mnt = cache->mnt,
.dentry = object->dentry
};
- _debug("trunc %llx -> %llx", i_size_read(d_inode(object->dentry)), object_size);
+ _debug("trunc %llx -> %llx", i_size, object_size);
+ trace_cachefiles_trunc(object, inode, i_size, object_size);
ret = vfs_truncate(&path, object_size);
if (ret < 0) {
cachefiles_io_error_obj(object, "Trunc-to-size failed");
@@ -186,8 +190,10 @@ static void cachefiles_update_object(struct fscache_object *_object)
}

object_size = round_up(object_size, CACHEFILES_DIO_BLOCK_SIZE);
- _debug("trunc %llx -> %llx", i_size_read(d_inode(object->dentry)), object_size);
- if (i_size_read(d_inode(object->dentry)) < object_size) {
+ i_size = i_size_read(inode);
+ _debug("trunc %llx -> %llx", i_size, object_size);
+ if (i_size < object_size) {
+ trace_cachefiles_trunc(object, inode, i_size, object_size);
ret = vfs_truncate(&path, object_size);
if (ret < 0) {
cachefiles_io_error_obj(object, "Trunc-to-dio-size failed");
diff --git a/fs/cachefiles/io.c b/fs/cachefiles/io.c
index 42e0d620d778..268e6f69ba9c 100644
--- a/fs/cachefiles/io.c
+++ b/fs/cachefiles/io.c
@@ -88,6 +88,7 @@ int cachefiles_read(struct fscache_object *obj,
goto presubmission_error_free;

fscache_get_io_request(req);
+ trace_cachefiles_read(object, file_inode(file), req);
ret = call_read_iter(file, &ki->iocb, iter);
switch (ret) {
case -EIOCBQUEUED:
@@ -198,6 +199,7 @@ int cachefiles_write(struct fscache_object *obj,
__sb_writers_release(inode->i_sb, SB_FREEZE_WRITE);

fscache_get_io_request(req);
+ trace_cachefiles_write(object, inode, req);
ret = call_write_iter(file, &ki->iocb, iter);
switch (ret) {
case -EIOCBQUEUED:
diff --git a/include/trace/events/cachefiles.h b/include/trace/events/cachefiles.h
index e7af1d683009..d83568e8fee8 100644
--- a/include/trace/events/cachefiles.h
+++ b/include/trace/events/cachefiles.h
@@ -351,6 +351,129 @@ TRACE_EVENT(cachefiles_coherency,
__entry->content)
);

+TRACE_EVENT(cachefiles_read,
+ TP_PROTO(struct cachefiles_object *obj,
+ struct inode *backer,
+ struct fscache_io_request *req),
+
+ TP_ARGS(obj, backer, req),
+
+ TP_STRUCT__entry(
+ __field(unsigned int, obj )
+ __field(unsigned int, backer )
+ __field(unsigned int, len )
+ __field(loff_t, pos )
+ ),
+
+ TP_fast_assign(
+ __entry->obj = obj->fscache.debug_id;
+ __entry->backer = backer->i_ino;
+ __entry->pos = req->pos;
+ __entry->len = req->len;
+ ),
+
+ TP_printk("o=%08x b=%08x p=%llx l=%x",
+ __entry->obj,
+ __entry->backer,
+ __entry->pos,
+ __entry->len)
+ );
+
+TRACE_EVENT(cachefiles_write,
+ TP_PROTO(struct cachefiles_object *obj,
+ struct inode *backer,
+ struct fscache_io_request *req),
+
+ TP_ARGS(obj, backer, req),
+
+ TP_STRUCT__entry(
+ __field(unsigned int, obj )
+ __field(unsigned int, backer )
+ __field(unsigned int, len )
+ __field(loff_t, pos )
+ ),
+
+ TP_fast_assign(
+ __entry->obj = obj->fscache.debug_id;
+ __entry->backer = backer->i_ino;
+ __entry->pos = req->pos;
+ __entry->len = req->len;
+ ),
+
+ TP_printk("o=%08x b=%08x p=%llx l=%x",
+ __entry->obj,
+ __entry->backer,
+ __entry->pos,
+ __entry->len)
+ );
+
+TRACE_EVENT(cachefiles_trunc,
+ TP_PROTO(struct cachefiles_object *obj, struct inode *backer,
+ loff_t from, loff_t to),
+
+ TP_ARGS(obj, backer, from, to),
+
+ TP_STRUCT__entry(
+ __field(unsigned int, obj )
+ __field(unsigned int, backer )
+ __field(loff_t, from )
+ __field(loff_t, to )
+ ),
+
+ TP_fast_assign(
+ __entry->obj = obj->fscache.debug_id;
+ __entry->backer = backer->i_ino;
+ __entry->from = from;
+ __entry->to = to;
+ ),
+
+ TP_printk("o=%08x b=%08x l=%llx->%llx",
+ __entry->obj,
+ __entry->backer,
+ __entry->from,
+ __entry->to)
+ );
+
+TRACE_EVENT(cachefiles_tmpfile,
+ TP_PROTO(struct cachefiles_object *obj, struct inode *backer),
+
+ TP_ARGS(obj, backer),
+
+ TP_STRUCT__entry(
+ __field(unsigned int, obj )
+ __field(unsigned int, backer )
+ ),
+
+ TP_fast_assign(
+ __entry->obj = obj->fscache.debug_id;
+ __entry->backer = backer->i_ino;
+ ),
+
+ TP_printk("o=%08x b=%08x",
+ __entry->obj,
+ __entry->backer)
+ );
+
+TRACE_EVENT(cachefiles_link,
+ TP_PROTO(struct cachefiles_object *obj, struct inode *backer),
+
+ TP_ARGS(obj, backer),
+
+ TP_STRUCT__entry(
+ __field(unsigned int, obj )
+ __field(unsigned int, backer )
+ ),
+
+ TP_fast_assign(
+ __entry->obj = obj->fscache.debug_id;
+ __entry->backer = backer->i_ino;
+ ),
+
+ TP_printk("o=%08x b=%08x",
+ __entry->obj,
+ __entry->backer)
+ );
+
#endif /* _TRACE_CACHEFILES_H */

/* This part must be outside protection */