Skip to contentSkip to conversation

relay: move remove_buf_file inside relay_close_buf

PATCH In review Dmitry Monakhov 2 participants 3 messages Apr 22, 2013 – Apr 30, 2013 Relay

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 relay: move remove_buf_file inside relay_close_buf

Hi,
Let someone please finally take care of this patch. Originally it was submitted here https://lkml.org/lkml/2010/2/28/103
This patch fix very annoying issue. I've got OK from Jens and Tom Zanussi but no one accept it. MAINTAINERS file has no info about relayfs. So I've added to CC all people which may be interested in that.

Quoted 1 line

From 1c0d96aece60a8a81c3f0cf1f681a5ff4333a2ff Mon Sep 17 00:00:00 2001

From: Dmitry Monakhov <[email protected]>
Date: Mon, 22 Apr 2013 11:41:41 +0400
Subject: [PATCH] relay: move remove_buf_file inside relay_close_buf

Currently remove_buf_file callback is called from from kobject release method. This result in follow issue:

# blktrace -d /dev/sda1 -d /dev/sda -o test

blktrace_setup()
dir = create_dir()
rchan = relay_open(dir,...)
->create_buf_file_callback
buf_file = debugfs_create_file(dir, )

Userspace will open buf_file.
Later we make a decision to stop tracing blktrace_down()
relay_close(rhcan) /* just decrement kobj reference */

                      /* since it is not zero then callback not called */

debugfs_remove(dir) /* FAIL due to non empty dir */

Later user space will close the file and file will be deleted, but directory still exist.
user_space_close()
->file_release
->release_buf_file_callback

     ->debugfs_remove(buf_file
## TESTCASE:
# blktrace -d /dev/sda1 -d /dev/sda -o test
# After that blktrace infrastructure will remain broken in
# an unusable state so: blktrace -d /dev/sda1 will not work.

In fact this is general issue, blktrace is just one of examples. We can not reliably remove parent dir until all users close the buf_file.

Solution: We don't have to wait that long. File should be deleted inside relay_close_buf().

---
 kernel/relay.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/relay.c +1 -1
index 01ab081..a0d2000 100644
@@ -234,7 +234,6 @@ static void relay_destroy_buf(struct rchan_buf *buf)
 static void relay_remove_buf(struct kref *kref)
 {
 	struct rchan_buf *buf = container_of(kref, struct rchan_buf, kref);
-	buf->chan->cb->remove_buf_file(buf->dentry);
 	relay_destroy_buf(buf);
 }
 
@@ -484,6 +483,7 @@ static void relay_close_buf(struct rchan_buf *buf)
 {
 	buf->finalized = 1;
 	del_timer_sync(&buf->timer);
+	buf->chan->cb->remove_buf_file(buf->dentry);
 	kref_put(&buf->kref, relay_remove_buf);
 }
 
Signature · 1 line
1.7.1
#1 lore raw

Re: [PATCH] relay: move remove_buf_file inside relay_close_buf PING..

On Mon, 22 Apr 2013 11:57:52 +0400, Dmitry Monakhov <[email protected]> wrote:
Non-text part: multipart/mixed

Quoted 1 line

Seriously. Am I an only one who use blktrace?
Jens can you please take it?

Quoted 77 lines

Hi,
Let someone please finally take care of this patch. Originally it was submitted here https://lkml.org/lkml/2010/2/28/103
This patch fix very annoying issue. I've got OK from Jens and Tom Zanussi but no one accept it. MAINTAINERS file has no info about relayfs. So I've added to CC all people which may be interested in that.

From 1c0d96aece60a8a81c3f0cf1f681a5ff4333a2ff Mon Sep 17 00:00:00 2001
From: Dmitry Monakhov <[email protected]>
Date: Mon, 22 Apr 2013 11:41:41 +0400
Subject: [PATCH] relay: move remove_buf_file inside relay_close_buf

Currently remove_buf_file callback is called from from kobject release method. This result in follow issue:

# blktrace -d /dev/sda1 -d /dev/sda -o test

blktrace_setup()
dir = create_dir()
rchan = relay_open(dir,...)
->create_buf_file_callback
buf_file = debugfs_create_file(dir, )

Userspace will open buf_file.
Later we make a decision to stop tracing blktrace_down()
relay_close(rhcan) /* just decrement kobj reference */

                      /* since it is not zero then callback not called */

debugfs_remove(dir) /* FAIL due to non empty dir */

Later user space will close the file and file will be deleted, but directory still exist.
user_space_close()
->file_release
->release_buf_file_callback

     ->debugfs_remove(buf_file
## TESTCASE:
# blktrace -d /dev/sda1 -d /dev/sda -o test
# After that blktrace infrastructure will remain broken in
# an unusable state so: blktrace -d /dev/sda1 will not work.

In fact this is general issue, blktrace is just one of examples. We can not reliably remove parent dir until all users close the buf_file.

Solution: We don't have to wait that long. File should be deleted inside relay_close_buf().

---
 kernel/relay.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/relay.c +1 -1
index 01ab081..a0d2000 100644
@@ -234,7 +234,6 @@ static void relay_destroy_buf(struct rchan_buf *buf)
 static void relay_remove_buf(struct kref *kref)
 {
 	struct rchan_buf *buf = container_of(kref, struct rchan_buf, kref);
-	buf->chan->cb->remove_buf_file(buf->dentry);
 	relay_destroy_buf(buf);
 }
 
@@ -484,6 +483,7 @@ static void relay_close_buf(struct rchan_buf *buf)
 {
 	buf->finalized = 1;
 	del_timer_sync(&buf->timer);
+	buf->chan->cb->remove_buf_file(buf->dentry);
 	kref_put(&buf->kref, relay_remove_buf);
 }
 
Signature · 1 line
1.7.1
maintainer
#2 lore raw

Re: [PATCH] relay: move remove_buf_file inside relay_close_buf PING..

Quoted 4 lines · Dmitry Monakhov

On Mon, 22 Apr 2013 11:57:52 +0400, Dmitry Monakhov <[email protected]> wrote:
Non-text part: multipart/mixed

Quoted 1 line

Seriously. Am I an only one who use blktrace?

I do :-)

Quoted 1 line

Jens can you please take it?

Thanks, will do.

Signature · 1 line
Jens Axboe