Re: [RFC][PATCH] sys_fallocate() system call

2007-03-21 Thread Amit K. Arora
On Sat, Mar 17, 2007 at 05:10:37AM -0600, Matthew Wilcox wrote:
 How about:
 
 asmlinkage long sys_fallocate(int fd, int mode, u32 off_low, u32 off_high,
   u32 len_low, u32 len_high);
 
 That way we all suffer equally ...

As suggested by you and Russel, I have made this change to the patch.
Here is how it looks like now. Please let me know if anyone has concerns
about passing arguments this way (breaking each loff_t into two u32s).

Signed-off-by: Amit K Arora [EMAIL PROTECTED]
---
 arch/i386/kernel/syscall_table.S |1 
 arch/x86_64/kernel/functionlist  |1 
 fs/open.c|   46 +++
 include/asm-i386/unistd.h|3 +-
 include/asm-powerpc/systbl.h |1 
 include/asm-powerpc/unistd.h |3 +-
 include/asm-x86_64/unistd.h  |4 ++-
 include/linux/fs.h   |7 +
 include/linux/syscalls.h |2 +
 9 files changed, 65 insertions(+), 3 deletions(-)

Index: linux-2.6.20.1/arch/i386/kernel/syscall_table.S
===
--- linux-2.6.20.1.orig/arch/i386/kernel/syscall_table.S
+++ linux-2.6.20.1/arch/i386/kernel/syscall_table.S
@@ -319,3 +319,4 @@ ENTRY(sys_call_table)
.long sys_move_pages
.long sys_getcpu
.long sys_epoll_pwait
+   .long sys_fallocate /* 320 */
Index: linux-2.6.20.1/fs/open.c
===
--- linux-2.6.20.1.orig/fs/open.c
+++ linux-2.6.20.1/fs/open.c
@@ -350,6 +350,52 @@ asmlinkage long sys_ftruncate64(unsigned
 }
 #endif
 
+asmlinkage long sys_fallocate(int fd, int mode, u32 off_low, u32 off_high,
+   u32 len_low, u32 len_high)
+{
+   struct file *file;
+   struct inode *inode;
+   loff_t offset, len;
+   long ret = -EINVAL;
+
+   offset = (off_high  32) + off_low;
+   len = (len_high  32) + len_low;
+
+   if (len == 0 || offset  0)
+   goto out;
+
+   ret = -EBADF;
+   file = fget(fd);
+   if (!file)
+   goto out;
+   if (!(file-f_mode  FMODE_WRITE))
+   goto out_fput;
+
+   inode = file-f_path.dentry-d_inode;
+
+   ret = -ESPIPE;
+   if (S_ISFIFO(inode-i_mode))
+   goto out_fput;
+
+   ret = -ENODEV;
+   if (!S_ISREG(inode-i_mode))
+   goto out_fput;
+
+   ret = -EFBIG;
+   if (offset + len  inode-i_sb-s_maxbytes)
+   goto out_fput;
+
+   if (inode-i_op  inode-i_op-fallocate)
+   ret = inode-i_op-fallocate(inode, mode, offset, len);
+   else
+   ret = -ENOSYS;
+out_fput:
+   fput(file);
+out:
+   return ret;
+}
+EXPORT_SYMBOL(sys_fallocate);
+
 /*
  * access() needs to use the real uid/gid, not the effective uid/gid.
  * We do this by temporarily clearing all FS-related capabilities and
Index: linux-2.6.20.1/include/asm-i386/unistd.h
===
--- linux-2.6.20.1.orig/include/asm-i386/unistd.h
+++ linux-2.6.20.1/include/asm-i386/unistd.h
@@ -325,10 +325,11 @@
 #define __NR_move_pages317
 #define __NR_getcpu318
 #define __NR_epoll_pwait   319
+#define __NR_fallocate 320
 
 #ifdef __KERNEL__
 
-#define NR_syscalls 320
+#define NR_syscalls 321
 
 #define __ARCH_WANT_IPC_PARSE_VERSION
 #define __ARCH_WANT_OLD_READDIR
Index: linux-2.6.20.1/include/linux/fs.h
===
--- linux-2.6.20.1.orig/include/linux/fs.h
+++ linux-2.6.20.1/include/linux/fs.h
@@ -263,6 +263,12 @@ extern int dir_notify_enable;
 #define SYNC_FILE_RANGE_WRITE  2
 #define SYNC_FILE_RANGE_WAIT_AFTER 4
 
+/*
+ * fallocate() modes
+ */
+#define FA_ALLOCATE0x1
+#define FA_DEALLOCATE  0x2
+
 #ifdef __KERNEL__
 
 #include linux/linkage.h
@@ -1124,6 +1130,7 @@ struct inode_operations {
ssize_t (*listxattr) (struct dentry *, char *, size_t);
int (*removexattr) (struct dentry *, const char *);
void (*truncate_range)(struct inode *, loff_t, loff_t);
+   int (*fallocate)(struct inode *, int, loff_t, loff_t);
 };
 
 struct seq_file;
Index: linux-2.6.20.1/include/linux/syscalls.h
===
--- linux-2.6.20.1.orig/include/linux/syscalls.h
+++ linux-2.6.20.1/include/linux/syscalls.h
@@ -602,6 +602,8 @@ asmlinkage long sys_get_robust_list(int 
 asmlinkage long sys_set_robust_list(struct robust_list_head __user *head,
size_t len);
 asmlinkage long sys_getcpu(unsigned __user *cpu, unsigned __user *node, struct 
getcpu_cache __user *cache);
+asmlinkage long sys_fallocate(int fd, int mode, u32 off_low, u32 off_high,
+   u32 len_low, u32 len_high);
 
 int kernel_execve(const char *filename, char *const argv[], char *const 
envp[]);
 
Index: 

Re: [RFC][PATCH] sys_fallocate() system call

2007-03-19 Thread Amit K. Arora
On Sat, Mar 17, 2007 at 04:33:50PM +1100, Stephen Rothwell wrote:
 On Fri, 16 Mar 2007 20:01:01 +0530 Amit K. Arora [EMAIL PROTECTED] wrote:
 
 
  +asmlinkage long sys_fallocate(int fd, int mode, loff_t offset, loff_t len);
 
  --- linux-2.6.20.1.orig/include/asm-powerpc/systbl.h
  +++ linux-2.6.20.1/include/asm-powerpc/systbl.h
  @@ -305,3 +305,4 @@ SYSCALL_SPU(faccessat)
   COMPAT_SYS_SPU(get_robust_list)
   COMPAT_SYS_SPU(set_robust_list)
   COMPAT_SYS(move_pages)
  +SYSCALL(fallocate)
 
 It is going to need to be a COMPAT_SYS call in powerpc because 32 bit
 powerpc will pass the two loff_t's in pairs of registers while
 64bit passes them in one register each.

Ok. Will make that change, unless it is decided to pass each loff_t
argument as two u32s. Thanks!

--
Regards,
Amit Arora
-
To unsubscribe from this list: send the line unsubscribe linux-ext4 in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC][PATCH] sys_fallocate() system call

2007-03-17 Thread Heiko Carstens
On Sat, Mar 17, 2007 at 05:07:06AM -0600, Matthew Wilcox wrote:
 On Sat, Mar 17, 2007 at 08:59:05PM +1100, Paul Mackerras wrote:
  ... but wouldn't work on 32-bit powerpc. :(  We would end up with a
  pad argument between fd and offset, giving 7 arguments in all
  (counting the loff_t's as 2), but we only support 6.
 
 Ditto mips and parisc.

Can't be. Or: mips supports 7 arguments and parisc doesn't pad.
Otherwise they couldn't have wired up

sys_sync_file_range(int fd, loff_t offset, loff_t nbytes, unsigned int flags)

But from what I read, it's currently not possible for 32-bit powerpc to
wire up the already present sync_file_range system call.
-
To unsubscribe from this list: send the line unsubscribe linux-ext4 in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC][PATCH] sys_fallocate() system call

2007-03-17 Thread Stephen Rothwell
On Sat, 17 Mar 2007 15:30:43 +0100 Heiko Carstens [EMAIL PROTECTED] wrote:

 sys_sync_file_range(int fd, loff_t offset, loff_t nbytes, unsigned int flags)

 But from what I read, it's currently not possible for 32-bit powerpc to
 wire up the already present sync_file_range system call.

32bit native is fine (as the ABI in user mode is the same as that in the
kernel).  For 32bit on a 64bit kernel you need the arch specific comapt
routine that I used in the patch I posteda little while ago,

--
Cheers,
Stephen Rothwell[EMAIL PROTECTED]
http://www.canb.auug.org.au/~sfr/


pgpVken1FSREN.pgp
Description: PGP signature


Re: [RFC][PATCH] sys_fallocate() system call

2007-03-17 Thread Russell King
On Fri, Mar 16, 2007 at 08:01:01PM +0530, Amit K. Arora wrote:
 Attached below is the patch which implements this system call. It has
 been currently implemented and tested on i386, ppc64 and x86_64
 architectures. I am facing some problems while trying to implement this
 on s390, and thus the delay. While I try to get it right on s390(x), we
 thought of posting this patch, so that we can save some time. Parallely
 we will work on getting the patch work on s390, and probably it will
 come as a separate patch.

I suggest reading the very end of arch/arm/kernel/sys_arm.c; I'd rather
avoid adding more and more hacks like that to the kernel if at all
possible.

One solution (already mentioned elsewhere) is that we start avoiding
passing 64-bit arguments and instead pass two 32-bit instead.  This
nicely avoids the alignment restrictions for 64-bit args in ABIs.

(The issue for ARM is that with anything other than the fd, mode,
offset, len layout we will have to deal with different ABI argument
layouts, or implement our own wrapper function as done for
sys_arm_sync_file_range.)

I think the problem comes down to what is the argument layout which
causes the least amount of problems for the complete set of architectures.
For ARM, that's the fd, mode, offset, len layout.

-- 
Russell King
 Linux kernel2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:
-
To unsubscribe from this list: send the line unsubscribe linux-ext4 in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html