Skip to contentSkip to conversation

fs: imgdafs: Add IMG DAFS filesystem for metag

PATCH Superseded James Hogan 2 participants 3 messages Mar 26, 2013 VFS

v6 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

PATCH v6 1/1 fs: imgdafs: Add IMG DAFS filesystem for metag

Add the IMG Debug Adapter File System (DAFS) for metag, which uses SWITCH operations to communicate with a file server on a host computer via a JTAG debug adapter.

Cc Alexander Viro <[email protected]>

---
v6:
* use file_inode() helper introduced in v3.9-rc1
* remove dafs_iops as it only contained directory methods
* add MODULE_ALIAS_FS()

v5:
* removed arch/metag changes (the arch/metag patchset it was previously part of is now mainline with those changes)

v4:
* clean up fscall similarly to chancall in tty/metag_da

v2:
* fixed fserrno problem (Al Viro)
* renamed to imgdafs

 fs/Kconfig           |   1 +
 fs/Makefile          |   1 +
 fs/imgdafs/Kconfig   |   6 +
 fs/imgdafs/Makefile  |   7 +
 fs/imgdafs/imgdafs.h |  80 +++++
 fs/imgdafs/inode.c   | 832 +++++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 927 insertions(+)
 create mode 100644 fs/imgdafs/Kconfig
 create mode 100644 fs/imgdafs/Makefile
 create mode 100644 fs/imgdafs/imgdafs.h
 create mode 100644 fs/imgdafs/inode.c
fs/Kconfig +1 -0
index 780725a..6deefc1 100644
@@ -211,6 +211,7 @@ source "fs/sysv/Kconfig"
 source "fs/ufs/Kconfig"
 source "fs/exofs/Kconfig"
 source "fs/f2fs/Kconfig"
+source "fs/imgdafs/Kconfig"
 
 endif # MISC_FILESYSTEMS
 
fs/Makefile +1 -0
index 9d53192..b070fca 100644
@@ -127,3 +127,4 @@ obj-$(CONFIG_F2FS_FS)		+= f2fs/
 obj-y				+= exofs/ # Multiple modules
 obj-$(CONFIG_CEPH_FS)		+= ceph/
 obj-$(CONFIG_PSTORE)		+= pstore/
+obj-$(CONFIG_IMGDAFS_FS)	+= imgdafs/
fs/imgdafs/Kconfig new file +6 -0
new file mode 100644
index 0000000..5293adb
@@ -0,0 +1,6 @@
+config IMGDAFS_FS
+	bool "Meta DA filesystem support"
+	depends on METAG_DA
+	help
+	  This enables the DA filesystem, which allows Linux to
+	  to access files on a system attached via a debug adapter.
fs/imgdafs/Makefile new file +7 -0
new file mode 100644
index 0000000..169a3c6
@@ -0,0 +1,7 @@
+#
+# Makefile for DAfs the Debug Adapter filesystem.
+#
+
+obj-$(CONFIG_IMGDAFS_FS) += imgdafs.o
+
+imgdafs-objs := inode.o
fs/imgdafs/imgdafs.h new file +80 -0

80 lines not on this page · raw message

fs/imgdafs/inode.c new file +832 -0

832 lines not on this page · raw message

Signature · 1 line
1.8.1.2
maintainer
#1 lore raw
Quoted 9 lines · James Hogan
fs/imgdafs/imgdafs.h new file +9 -0
+struct da_stat {
+	short st_dev;
+	unsigned short st_ino;
+	unsigned st_mode;
+	unsigned short st_nlink;
+	unsigned short st_uid;
+	unsigned short st_gid;
+	short st_rdev;
+	int st_size;

fs/imgdafs/imgdafs.h line 70

Quoted 10 lines
fs/imgdafs/imgdafs.h new file +10 -0
+	int st_atime;
+	int st_spare1;
+	int st_mtime;
+	int st_spare2;
+	int st_ctime;
+	int st_spare3;
+	int st_blksize;
+	int st_blocks;
+	int st_spare4[2];
+};

Please, use explicitly-sized types.

fs/imgdafs/imgdafs.h line 78

Quoted 5 lines
fs/imgdafs/imgdafs.h new file +5 -0
+struct da_finddata {
+	unsigned long size;
+	unsigned long attrib;
+	char name[260];
+};

... especially for this - unlike int and short, long really is arch-dependent. And yes, I realize that this thing is arch-specific, but...

fs/imgdafs/inode.c line 58

Quoted 3 lines
fs/imgdafs/inode.c new file +3 -0
+struct dafs_inode_info {
+	int fd;
+	int mode;

umm... int or fmode_t?

fs/imgdafs/inode.c line 78

Quoted 4 lines
fs/imgdafs/inode.c new file +3 -0
+	struct inode vfs_inode;
+};
 
+#define DAFS_SUPER_MAGIC 0xdadadaf5

-> linux/magic.h

fs/imgdafs/inode.c line 114

Quoted 7 lines
fs/imgdafs/inode.c new file +7 -0
+static char *dentry_name(struct dentry *dentry)
+{
+	char *name = __getname();
+	if (!name)
+		return NULL;
+
+	return __dentry_name(dentry, name); /* will unlock */

will unlock what?

fs/imgdafs/inode.c line 163

Quoted 7 lines
fs/imgdafs/inode.c new file +7 -0
+	hi = kzalloc(sizeof(*hi), GFP_KERNEL);
+	if (hi == NULL)
+		return NULL;
+
+	hi->fd = -1;
+	inode_init_once(&hi->vfs_inode);
+	return &hi->vfs_inode;

Umm... kzalloc() looks odd, seeing that you proceed to initialize two fields out of 3 (including the really big one) explicitly...

fs/imgdafs/inode.c line 204

Quoted 4 lines
fs/imgdafs/inode.c new file +4 -0
+static int open_dir(char *path, struct da_finddata *finddata, int *fserrno)
+{
+	int len = strlen(path);
+	char buf[len + 3];

Bad idea, considering that strlen(path) is user-controlled and can theoretically go up to 4Kb...

fs/imgdafs/inode.c line 228

Quoted 3 lines
fs/imgdafs/inode.c new file +3 -0
+static int dafs_readdir(struct file *file, void *ent, filldir_t filldir)
+{
+	struct inode *inode = file->f_path.dentry->d_inode;

minor nit, but... that's file_inode(file)

fs/imgdafs/inode.c line 240

Quoted 4 lines
fs/imgdafs/inode.c new file +4 -0
+	name = dentry_name(file->f_path.dentry);
+	if (name == NULL)
+		return -ENOMEM;
+	handle = open_dir(name, &finddata, &fserrno);

... and what if the sucker's parent gets renamed between dentry_name() and open_dir()? The same goes for the rest of dentry_name() users, actually.

Quoted 9 lines
fs/imgdafs/inode.c new file +9 -0
+static int dafs_rename(struct inode *from_ino, struct dentry *from,
+		  struct inode *to_ino, struct dentry *to)
+{
+	char *from_name, *to_name;
+	int err;
+
+	from_name = dentry_name(from);
+	if (from_name == NULL)
+		return -ENOMEM;

fs/imgdafs/inode.c line 752

Quoted 10 lines
fs/imgdafs/inode.c new file +10 -0
+	to_name = dentry_name(to);
+	if (to_name == NULL) {
+		__putname(from_name);
+		return -ENOMEM;
+	}
+	err = -EINVAL;
+	__putname(from_name);
+	__putname(to_name);
+	return err;
+}

Aha. No rename(2), IOW. Is one planned?

#2 lore raw

Thanks for reviewing Al...

Quoted 9 lines · Al Viro

fs/imgdafs/imgdafs.h line 78

Quoted 5 lines · James Hogan
fs/imgdafs/imgdafs.h new file +5 -0
+struct da_finddata {
+     unsigned long size;
+     unsigned long attrib;
+     char name[260];
+};

... especially for this - unlike int and short, long really is arch-dependent. And yes, I realize that this thing is arch-specific, but...

Yes, agreed.

Quoted 6 lines

fs/imgdafs/inode.c line 58

Quoted 4 lines
fs/imgdafs/inode.c new file +3 -0
+struct dafs_inode_info {
+     int fd;
+     int mode;

umm... int or fmode_t?

Indeed. The same update to hostfs during v2.6.28 was missed :-(

Quoted 7 lines

fs/imgdafs/inode.c line 78

Quoted 5 lines
fs/imgdafs/inode.c new file +3 -0
+     struct inode vfs_inode;
+};
 
+#define DAFS_SUPER_MAGIC 0xdadadaf5

-> linux/magic.h

Okay. hostfs has the same problem.

Quoted 10 lines

fs/imgdafs/inode.c line 114

Quoted 8 lines
fs/imgdafs/inode.c new file +7 -0
+static char *dentry_name(struct dentry *dentry)
+{
+     char *name = __getname();
+     if (!name)
+             return NULL;
+
+     return __dentry_name(dentry, name); /* will unlock */

will unlock what?

The change adding this was based on hostfs, which had the comment added by you in e9193059b1b3733695d5b80e667778311695aa73 ("hostfs: fix races in dentry_name() and inode_name()"), along with a spin_lock just before it. The spin_lock (and unlock in __dentry_name) was subsequently removed in ec2447c278ee973d35f38e53ca16ba7f965ae33d ("hostfs: simplify locking"), so the comment is no longer relevant. I'll remove it.

Quoted 11 lines

fs/imgdafs/inode.c line 163

Quoted 8 lines
fs/imgdafs/inode.c new file +7 -0
+     hi = kzalloc(sizeof(*hi), GFP_KERNEL);
+     if (hi == NULL)
+             return NULL;
+
+     hi->fd = -1;
+     inode_init_once(&hi->vfs_inode);
+     return &hi->vfs_inode;

Umm... kzalloc() looks odd, seeing that you proceed to initialize two fields out of 3 (including the really big one) explicitly...

Agreed, another issue in common with hostfs. I'll fix.

Quoted 8 lines

fs/imgdafs/inode.c line 204

Quoted 5 lines
fs/imgdafs/inode.c new file +4 -0
+static int open_dir(char *path, struct da_finddata *finddata, int *fserrno)
+{
+     int len = strlen(path);
+     char buf[len + 3];

Bad idea, considering that strlen(path) is user-controlled and can theoretically go up to 4Kb...

Ouch yes, I'll convert it to use kmalloc/kfree (the fs operations are horribly slow anyway so it's never a performance issue).

Quoted 6 lines

fs/imgdafs/inode.c line 228

Quoted 4 lines
fs/imgdafs/inode.c new file +3 -0
+static int dafs_readdir(struct file *file, void *ent, filldir_t filldir)
+{
+     struct inode *inode = file->f_path.dentry->d_inode;

minor nit, but... that's file_inode(file)

Ooh yes.

Quoted 8 lines

fs/imgdafs/inode.c line 240

Quoted 5 lines
fs/imgdafs/inode.c new file +4 -0
+     name = dentry_name(file->f_path.dentry);
+     if (name == NULL)
+             return -ENOMEM;
+     handle = open_dir(name, &finddata, &fserrno);

... and what if the sucker's parent gets renamed between dentry_name() and open_dir()? The same goes for the rest of dentry_name() users, actually.

It would seem impossible to protect against this happening from the file server side, and as for the Linux side...

Quoted 14 lines
Quoted 14 lines
fs/imgdafs/inode.c new file +13 -0
+static int dafs_rename(struct inode *from_ino, struct dentry *from,
+               struct inode *to_ino, struct dentry *to)
+{
+     char *from_name, *to_name;
+     int err;
+
+     from_name = dentry_name(from);
+     if (from_name == NULL)
+             return -ENOMEM;
+     to_name = dentry_name(to);
+     if (to_name == NULL) {
+             __putname(from_name);
+             return -ENOMEM;
Quoted 8 lines

fs/imgdafs/inode.c line 666

Quoted 6 lines
fs/imgdafs/inode.c new file +6 -0
+     }
+     err = -EINVAL;
+     __putname(from_name);
+     __putname(to_name);
+     return err;
+}

Aha. No rename(2), IOW. Is one planned?

Hmm, indeed it appears a rename DAFS operation hasn't been defined. I'll double check that tomorrow. DAFS is usually used for just copying data to/from a target (e.g. an fpga with no other connectivity) so the lack of rename isn't usually a problem.

I'll fix up these issues (and do some separate patches for hostfs too).

Thanks
James