public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Christoph Rohland <cr@sap.com>
To: "David L. Parsley" <parsley@linuxjedi.org>
Cc: linux-kernel@vger.kernel.org
Subject: [Patch] inline symlinks for tmpfs
Date: 05 May 2001 09:48:26 +0200	[thread overview]
Message-ID: <m3elu4rj12.fsf_-_@linux.local> (raw)
In-Reply-To: <Pine.GSO.4.21.0104240639580.6992-100000@weyl.math.psu.edu> <m3n196v2un.fsf@linux.local> <3AE5AF68.404AEF0E@linuxjedi.org>
In-Reply-To: <3AE5AF68.404AEF0E@linuxjedi.org>

[-- Attachment #1: Type: text/plain, Size: 307 bytes --]

Hi David,

On Tue, 24 Apr 2001, David L. Parsley wrote:
>> OK I will do that for tmpfs soon. And I will do the symlink
>> inlining with that patch.

OK, here comes the patch for the symlink inlining. It is on top of my
previous patch to encapsulate access to the private inode info.

Greetings
		Christoph


[-- Attachment #2: patch-inline_symlink --]
[-- Type: text/plain, Size: 4567 bytes --]

diff -uNr 2.4.4-mmap_write-SHMEM_I/mm/shmem.c 2.4.4-mmap_write-SHMEM_I-symlink/mm/shmem.c
--- 2.4.4-mmap_write-SHMEM_I/mm/shmem.c	Fri May  4 21:32:22 2001
+++ 2.4.4-mmap_write-SHMEM_I-symlink/mm/shmem.c	Fri May  4 21:37:34 2001
@@ -41,7 +41,6 @@
 static struct inode_operations shmem_inode_operations;
 static struct file_operations shmem_dir_operations;
 static struct inode_operations shmem_dir_inode_operations;
-static struct inode_operations shmem_symlink_inode_operations;
 static struct vm_operations_struct shmem_vm_ops;
 
 LIST_HEAD (shmem_inodes);
@@ -205,11 +204,13 @@
 {
 	struct shmem_sb_info *info = &inode->i_sb->u.shmem_sb;
 
-	spin_lock (&shmem_ilock);
-	list_del (&SHMEM_I(inode)->list);
-	spin_unlock (&shmem_ilock);
 	inode->i_size = 0;
-	shmem_truncate (inode);
+	if (inode->i_op->truncate == shmem_truncate){ 
+		spin_lock (&shmem_ilock);
+		list_del (&SHMEM_I(inode)->list);
+		spin_unlock (&shmem_ilock);
+		shmem_truncate(inode);
+	}
 	spin_lock (&info->stat_lock);
 	info->free_inodes++;
 	spin_unlock (&info->stat_lock);
@@ -532,6 +533,9 @@
 		case S_IFREG:
 			inode->i_op = &shmem_inode_operations;
 			inode->i_fop = &shmem_file_operations;
+			spin_lock (&shmem_ilock);
+			list_add (&SHMEM_I(inode)->list, &shmem_inodes);
+			spin_unlock (&shmem_ilock);
 			break;
 		case S_IFDIR:
 			inode->i_nlink++;
@@ -539,17 +543,17 @@
 			inode->i_fop = &shmem_dir_operations;
 			break;
 		case S_IFLNK:
-			inode->i_op = &shmem_symlink_inode_operations;
 			break;
 		}
-		spin_lock (&shmem_ilock);
-		list_add (&SHMEM_I(inode)->list, &shmem_inodes);
-		spin_unlock (&shmem_ilock);
 	}
 	return inode;
 }
 
 #ifdef CONFIG_TMPFS
+
+static struct inode_operations shmem_symlink_inode_operations;
+static struct inode_operations shmem_symlink_inline_operations;
+
 static ssize_t
 shmem_file_write(struct file *file,const char *buf,size_t count,loff_t *ppos)
 {
@@ -930,33 +934,54 @@
 	struct inode *inode;
 	struct page *page;
 	char *kaddr;
+	struct shmem_inode_info * info;
 
 	error = shmem_mknod(dir, dentry, S_IFLNK | S_IRWXUGO, 0);
 	if (error)
 		return error;
 
-	len = strlen(symname);
+	len = strlen(symname) + 1;
 	if (len > PAGE_SIZE)
 		return -ENAMETOOLONG;
-		
+
 	inode = dentry->d_inode;
-	down(&inode->i_sem);
-	page = shmem_getpage_locked(SHMEM_I(inode), inode, 0);
-	if (IS_ERR(page))
-		goto fail;
-	kaddr = kmap(page);
-	memcpy(kaddr, symname, len);
-	kunmap(page);
+	info = SHMEM_I(inode);
 	inode->i_size = len;
-	SetPageDirty(page);
-	UnlockPage(page);
-	page_cache_release(page);
-	up(&inode->i_sem);
+	if (len <= sizeof(struct shmem_inode_info)) {
+		/* do it inline */
+		memcpy(info, symname, len);
+		inode->i_op = &shmem_symlink_inline_operations;
+	} else {
+		spin_lock (&shmem_ilock);
+		list_add (&info->list, &shmem_inodes);
+		spin_unlock (&shmem_ilock);
+		down(&inode->i_sem);
+		page = shmem_getpage_locked(info, inode, 0);
+		if (IS_ERR(page)) {
+			up(&inode->i_sem);
+			return PTR_ERR(page);
+		}
+		kaddr = kmap(page);
+		memcpy(kaddr, symname, len);
+		kunmap(page);
+		SetPageDirty(page);
+		UnlockPage(page);
+		page_cache_release(page);
+		up(&inode->i_sem);
+		inode->i_op = &shmem_symlink_inode_operations;
+	}
 	dir->i_ctime = dir->i_mtime = CURRENT_TIME;
 	return 0;
-fail:
-	up(&inode->i_sem);
-	return PTR_ERR(page);
+}
+
+static int shmem_readlink_inline(struct dentry *dentry, char *buffer, int buflen)
+{
+	return vfs_readlink(dentry,buffer,buflen, (const char *)SHMEM_I(dentry->d_inode));
+}
+
+static int shmem_follow_link_inline(struct dentry *dentry, struct nameidata *nd)
+{
+	return vfs_follow_link(nd, (const char *)SHMEM_I(dentry->d_inode));
 }
 
 static int shmem_readlink(struct dentry *dentry, char *buffer, int buflen)
@@ -986,6 +1011,17 @@
 	return res;
 }
 
+static struct inode_operations shmem_symlink_inline_operations = {
+	readlink:	shmem_readlink_inline,
+	follow_link:	shmem_follow_link_inline,
+};
+
+static struct inode_operations shmem_symlink_inode_operations = {
+	truncate:	shmem_truncate,
+	readlink:	shmem_readlink,
+	follow_link:	shmem_follow_link,
+};
+
 static int shmem_parse_options(char *options, int *mode, unsigned long * blocks, unsigned long *inodes)
 {
 	char *this_char, *value;
@@ -1118,14 +1154,6 @@
 
 static struct inode_operations shmem_inode_operations = {
 	truncate:	shmem_truncate,
-};
-
-static struct inode_operations shmem_symlink_inode_operations = {
-	truncate:	shmem_truncate,
-#ifdef CONFIG_TMPFS
-	readlink:	shmem_readlink,
-	follow_link:	shmem_follow_link,
-#endif
 };
 
 static struct file_operations shmem_dir_operations = {

  reply	other threads:[~2001-05-05  8:08 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-04-22 16:32 hundreds of mount --bind mountpoints? David L. Parsley
2001-04-22 16:41 ` Alexander Viro
2001-04-23 11:43 ` Christoph Rohland
2001-04-23 13:17   ` Ingo Oeser
2001-04-23 14:54     ` Christoph Rohland
2001-04-23 15:23       ` Ingo Oeser
2001-04-23 15:36         ` Alexander Viro
2001-04-23 20:45           ` Ingo Oeser
2001-04-23 20:56             ` Christoph Hellwig
2001-04-23 22:00               ` Ingo Oeser
2001-04-23 22:10                 ` Alexander Viro
2001-04-23 21:19             ` Richard Gooch
2001-04-23 22:42               ` Albert D. Cahalan
2001-04-23 22:49                 ` Richard Gooch
2001-04-23 23:07                   ` Alexander Viro
2001-04-23 23:13                     ` Richard Gooch
2001-04-23 23:24                     ` Rik van Riel
2001-04-23 22:47             ` Andreas Dilger
2001-04-24  1:37             ` Jan Harkes
2001-04-24  2:53               ` Alexander Viro
2001-04-24  9:58                 ` David Woodhouse
2001-04-24 10:07                   ` Alexander Viro
2001-04-24 10:19                     ` David Woodhouse
2001-04-24 10:35                     ` Christoph Rohland
2001-04-24 10:54                       ` Alexander Viro
2001-04-24 12:51                         ` David Woodhouse
2001-04-24 13:34                         ` Christoph Rohland
2001-04-24 16:52                           ` David L. Parsley
2001-05-05  7:48                             ` Christoph Rohland [this message]
2001-05-04 19:17                           ` [Patch] encapsulate shmem access to shmem_inode_info Christoph Rohland
     [not found]                             ` <3AF405FC.11D37FEB@bellsouth.net>
2001-05-06 13:58                               ` [Resend] Collection of tmpfs patches Christoph Rohland
2001-04-24 16:04                         ` Can't read SCSI TAPE Masaki Tsuji
2001-04-24 18:36                         ` hundreds of mount --bind mountpoints? Andreas Dilger
2001-04-24 18:49                           ` Alexander Viro
2001-04-24 19:11                             ` Andreas Dilger
2001-04-24 22:01                             ` Ingo Oeser
2001-04-24 21:59                 ` Trond Myklebust
2001-04-24 22:09                   ` Alexander Viro
2001-04-24 22:31                     ` Trond Myklebust
2001-04-24  6:33           ` Christoph Rohland
2001-04-23 14:08   ` David L. Parsley
2001-04-23 14:14     ` Alexander Viro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3elu4rj12.fsf_-_@linux.local \
    --to=cr@sap.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=parsley@linuxjedi.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox