* get device from file struct @ 2006-12-11 15:22 Silviu Craciunas 2006-12-11 18:34 ` Brice Goglin 0 siblings, 1 reply; 11+ messages in thread From: Silviu Craciunas @ 2006-12-11 15:22 UTC (permalink / raw) To: linux-kernel quick question for the gurus.. is it possible to determine the hardware device from a file struct during read/write system call. For example in fs/read_write.c when doing a vfs_read. thanks ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: get device from file struct 2006-12-11 15:22 get device from file struct Silviu Craciunas @ 2006-12-11 18:34 ` Brice Goglin 2006-12-12 9:04 ` Silviu Craciunas 0 siblings, 1 reply; 11+ messages in thread From: Brice Goglin @ 2006-12-11 18:34 UTC (permalink / raw) To: silviu.craciunas; +Cc: linux-kernel Silviu Craciunas wrote: > quick question for the gurus.. is it possible to determine the hardware > device from a file struct during read/write system call. For example in > fs/read_write.c when doing a vfs_read. > file->f_dentry->d_inode gives you the inode. If the inode is on top of a block device, inode->i_bdev gives you a struct block_device that might help you. Brice ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: get device from file struct 2006-12-11 18:34 ` Brice Goglin @ 2006-12-12 9:04 ` Silviu Craciunas 2006-12-13 9:59 ` Jan Engelhardt 0 siblings, 1 reply; 11+ messages in thread From: Silviu Craciunas @ 2006-12-12 9:04 UTC (permalink / raw) To: Brice Goglin; +Cc: linux-kernel On Mon, 2006-12-11 at 19:34 +0100, Brice Goglin wrote: > Silviu Craciunas wrote: > > quick question for the gurus.. is it possible to determine the hardware > > device from a file struct during read/write system call. For example in > > fs/read_write.c when doing a vfs_read. > > > > file->f_dentry->d_inode gives you the inode. If the inode is on top of a > block device, inode->i_bdev gives you a struct block_device that might > help you. > > Brice thanks for the reply, the block device can be determined with the major and minor numbers , what I would be more interested in is if one can get the net_device struct from the file struct silviu ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: get device from file struct 2006-12-12 9:04 ` Silviu Craciunas @ 2006-12-13 9:59 ` Jan Engelhardt 2006-12-13 10:37 ` Silviu Craciunas 0 siblings, 1 reply; 11+ messages in thread From: Jan Engelhardt @ 2006-12-13 9:59 UTC (permalink / raw) To: Silviu Craciunas; +Cc: Brice Goglin, linux-kernel >thanks for the reply, the block device can be determined with the major >and minor numbers , what I would be more interested in is if one can get >the net_device struct from the file struct Just how are you supposed to match files and network devices? -`J' -- ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: get device from file struct 2006-12-13 9:59 ` Jan Engelhardt @ 2006-12-13 10:37 ` Silviu Craciunas 2006-12-13 11:03 ` Jan Engelhardt 0 siblings, 1 reply; 11+ messages in thread From: Silviu Craciunas @ 2006-12-13 10:37 UTC (permalink / raw) To: Jan Engelhardt; +Cc: linux-kernel On Wed, 2006-12-13 at 10:59 +0100, Jan Engelhardt wrote: > >thanks for the reply, the block device can be determined with the major > >and minor numbers , what I would be more interested in is if one can get > >the net_device struct from the file struct > > Just how are you supposed to match files and network devices? > > > -`J' from the struct file you can get the struct socket and from there to the struct sock . What I would like to find out is where the data is coming from (read) and where it is going to(write) or if it is even possible to find the net device out using the struct file. Silviu ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: get device from file struct 2006-12-13 10:37 ` Silviu Craciunas @ 2006-12-13 11:03 ` Jan Engelhardt 2006-12-13 12:28 ` Silviu Craciunas 0 siblings, 1 reply; 11+ messages in thread From: Jan Engelhardt @ 2006-12-13 11:03 UTC (permalink / raw) To: Silviu Craciunas; +Cc: linux-kernel >> >thanks for the reply, the block device can be determined with the major >> >and minor numbers , what I would be more interested in is if one can get >> >the net_device struct from the file struct >> >> Just how are you supposed to match files and network devices? >> > >from the struct file you can get the struct socket and from there to the >struct sock . That only applies when using PF_LOCAL sockets. >What I would like to find out is where the data is coming >from (read) and where it is going to(write) or if it is even possible to >find the net device out using the struct file. I really don't get what you want. Suppose a daemon reads from a socket (PF_INET), then there is a file descriptor to sockfs (look into /proc/$$/fd/). Well, then you may be able to get the struct file for that socket, but it does not connect to a regular file (S_IFREG) at all. -`J' -- ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: get device from file struct 2006-12-13 11:03 ` Jan Engelhardt @ 2006-12-13 12:28 ` Silviu Craciunas 2006-12-13 19:19 ` Jan Engelhardt 0 siblings, 1 reply; 11+ messages in thread From: Silviu Craciunas @ 2006-12-13 12:28 UTC (permalink / raw) To: Jan Engelhardt; +Cc: linux-kernel On Wed, 2006-12-13 at 12:03 +0100, Jan Engelhardt wrote: > >> >thanks for the reply, the block device can be determined with the major > >> >and minor numbers , what I would be more interested in is if one can get > >> >the net_device struct from the file struct > >> > >> Just how are you supposed to match files and network devices? > >> > > > >from the struct file you can get the struct socket and from there to the > >struct sock . > > That only applies when using PF_LOCAL sockets. > > >What I would like to find out is where the data is coming > >from (read) and where it is going to(write) or if it is even possible to > >find the net device out using the struct file. > > I really don't get what you want. > > Suppose a daemon reads from a socket (PF_INET), then there is a file descriptor > to sockfs (look into /proc/$$/fd/). Well, then you may be able to get the > struct file for that socket, but it does not connect to a regular file > (S_IFREG) at all. > > > -`J' in fs/read_write.c, the vfs_read function does: file->f_op->read(file, buf, count, pos); after this call is it possible to determine where the data is coming from? e.g., the first hard disk, a pipe or from a socket. If it is a socket we are interested from which device (eth0, eth1, lo, ...) the data was received. silviu ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: get device from file struct 2006-12-13 12:28 ` Silviu Craciunas @ 2006-12-13 19:19 ` Jan Engelhardt 2006-12-13 23:53 ` Stephen Hemminger 0 siblings, 1 reply; 11+ messages in thread From: Jan Engelhardt @ 2006-12-13 19:19 UTC (permalink / raw) To: Silviu Craciunas; +Cc: linux-kernel >in fs/read_write.c, the vfs_read function does: > >file->f_op->read(file, buf, count, pos); > >after this call is it possible to determine where the >data is coming from? >e.g., the first hard disk, a pipe or from a socket. For hard disks: file->f_dentry->d_inode->d_sb->s_bdev gives you the block device in case it is a non-virtual filesystem. For pipes/sockets I do not know of a may to go from a filp to a struct sock or struct socket. >If it is a socket we are interested >from which device (eth0, eth1, lo, ...) the data was received. I do not think that is possible either. -`J' -- ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: get device from file struct 2006-12-13 19:19 ` Jan Engelhardt @ 2006-12-13 23:53 ` Stephen Hemminger 2006-12-14 13:03 ` Silviu Craciunas 0 siblings, 1 reply; 11+ messages in thread From: Stephen Hemminger @ 2006-12-13 23:53 UTC (permalink / raw) To: linux-kernel On Wed, 13 Dec 2006 20:19:51 +0100 (MET) Jan Engelhardt <jengelh@linux01.gwdg.de> wrote: > > >in fs/read_write.c, the vfs_read function does: > > > >file->f_op->read(file, buf, count, pos); > > > >after this call is it possible to determine where the > >data is coming from? > >e.g., the first hard disk, a pipe or from a socket. > > For hard disks: > file->f_dentry->d_inode->d_sb->s_bdev gives you the block device > in case it is a non-virtual filesystem. > > For pipes/sockets I do not know of a may to go from a filp to a > struct sock or struct socket. > > >If it is a socket we are interested > >from which device (eth0, eth1, lo, ...) the data was received. > > I do not think that is possible either. The connection between file and network device is through many layers and there is no direct binding. It could be 0 to N interfaces and even be data dependent. -- Stephen Hemminger <shemminger@osdl.org> ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: get device from file struct 2006-12-13 23:53 ` Stephen Hemminger @ 2006-12-14 13:03 ` Silviu Craciunas 2006-12-14 18:45 ` Stephen Hemminger 0 siblings, 1 reply; 11+ messages in thread From: Silviu Craciunas @ 2006-12-14 13:03 UTC (permalink / raw) To: Stephen Hemminger; +Cc: linux-kernel On Wed, 2006-12-13 at 15:53 -0800, Stephen Hemminger wrote: > The connection between file and network device is through many > layers and there is no direct binding. It could be 0 to N interfaces > and even be data dependent. you mean protocol dependent? yes,it goes trough the layer of the vfs but I thought there may be a way to get to the struct net_device from the struct file. You have the dev_base which contains all devices and in the net_device there is the ifindex which is the unique identifier. I guess there is no way to know the ifindex directly from a socket struct. thanks silviu ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: get device from file struct 2006-12-14 13:03 ` Silviu Craciunas @ 2006-12-14 18:45 ` Stephen Hemminger 0 siblings, 0 replies; 11+ messages in thread From: Stephen Hemminger @ 2006-12-14 18:45 UTC (permalink / raw) To: silviu.craciunas; +Cc: linux-kernel On Thu, 14 Dec 2006 14:03:28 +0100 Silviu Craciunas <silviu.craciunas@sbg.ac.at> wrote: > On Wed, 2006-12-13 at 15:53 -0800, Stephen Hemminger wrote: > > The connection between file and network device is through many > > layers and there is no direct binding. It could be 0 to N interfaces > > and even be data dependent. > > you mean protocol dependent? yes,it goes trough the layer of the vfs but > I thought there may be a way to get to the struct net_device from the > struct file. You have the dev_base which contains all devices and in the > net_device there is the ifindex which is the unique identifier. I guess > there is no way to know the ifindex directly from a socket struct. > > thanks > silviu > You can have things like netfilter and traffic classifiers that look at packet. -- Stephen Hemminger <shemminger@osdl.org> ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2006-12-14 18:46 UTC | newest] Thread overview: 11+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2006-12-11 15:22 get device from file struct Silviu Craciunas 2006-12-11 18:34 ` Brice Goglin 2006-12-12 9:04 ` Silviu Craciunas 2006-12-13 9:59 ` Jan Engelhardt 2006-12-13 10:37 ` Silviu Craciunas 2006-12-13 11:03 ` Jan Engelhardt 2006-12-13 12:28 ` Silviu Craciunas 2006-12-13 19:19 ` Jan Engelhardt 2006-12-13 23:53 ` Stephen Hemminger 2006-12-14 13:03 ` Silviu Craciunas 2006-12-14 18:45 ` Stephen Hemminger
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox