* [PATCH] Simplification of inode initialization
@ 2014-11-26 23:09 Juan Perez-Sanchez
2014-11-27 16:51 ` Jody Bruchon
0 siblings, 1 reply; 2+ messages in thread
From: Juan Perez-Sanchez @ 2014-11-26 23:09 UTC (permalink / raw)
To: linux-8086
[-- Attachment #1: Type: text/plain, Size: 619 bytes --]
Hi,
Initialization of inode structures was done in functions
get_empty_inode() and minix_new_inode(). But some
initializations were repeated at later stages.
The attached patch puts rationality to the initialization
of inode structures, placing initial values at the
earliest possible place and removing repeated initializations.
Also the simplification of several functions in the
fs/minix directory and prepare function get_pipe_inode()
for a future implementation of named pipes.
The new functions are simpler, easier to understand with
smaller code size.
Code size was reduced by 144 bytes.
Greetings,
Juan
[-- Attachment #2: elks-2g.patch --]
[-- Type: text/x-patch, Size: 9189 bytes --]
diff -Nur elks.orig/fs/inode.c elks/fs/inode.c
--- elks.orig/fs/inode.c 2014-11-25 19:15:51.000000000 -0600
+++ elks/fs/inode.c 2014-11-26 14:34:45.000000000 -0600
@@ -412,6 +412,7 @@
#endif
clear_inode(inode);
inode->i_count = inode->i_nlink = 1;
+ inode->i_uid = current->euid;
#ifdef BLOAT_FS
inode->i_version = ++event;
#endif
@@ -431,21 +432,21 @@
extern struct inode_operations pipe_inode_operations;
if ((inode = get_empty_inode())) {
+ inode->i_mode |= S_IFIFO | S_IRUSR | S_IWUSR;
+ inode->i_op = &pipe_inode_operations;
+ inode->i_gid = (__u8) current->egid;
+ inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
+
if (!(PIPE_BASE(*inode) = get_pipe_mem())) {
iput(inode);
return NULL;
}
- inode->i_op = &pipe_inode_operations;
- inode->i_count = 2; /* sum of readers/writers */
+ (inode->i_count)++; /* sum of readers/writers */
+ inode->i_pipe = 1;
PIPE_START(*inode) = PIPE_LEN(*inode) = 0;
PIPE_RD_OPENERS(*inode) = PIPE_WR_OPENERS(*inode) = 0;
PIPE_READERS(*inode) = PIPE_WRITERS(*inode) = 1;
PIPE_LOCK(*inode) = 0;
- inode->i_pipe = 1;
- inode->i_mode |= S_IFIFO | S_IRUSR | S_IWUSR;
- inode->i_uid = current->euid;
- inode->i_gid = (__u8) current->egid;
- inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
#if 0
inode->i_blksize = PAGE_SIZE;
diff -Nur elks.orig/fs/minix/bitmap.c elks/fs/minix/bitmap.c
--- elks.orig/fs/minix/bitmap.c 2014-11-16 08:20:56.000000000 -0600
+++ elks/fs/minix/bitmap.c 2014-11-26 14:10:01.000000000 -0600
@@ -198,7 +198,7 @@
unmap_buffer(bh);
}
-struct inode *minix_new_inode(struct inode *dir)
+struct inode *minix_new_inode(struct inode *dir, __u16 mode)
{
register struct inode *inode;
register struct buffer_head *bh;
@@ -209,6 +209,10 @@
return NULL;
inode->i_sb = dir->i_sb;
inode->i_flags = inode->i_sb->s_flags;
+ if((S_ISDIR(mode)) && (dir->i_mode & S_ISGID))
+ mode |= S_ISGID;
+ inode->i_mode = mode;
+ minix_set_ops(inode);
j = 8192;
for (i = 0; i < 8; i++)
if ((bh = inode->i_sb->u.minix_sb.s_imap[i]) != NULL) {
@@ -232,15 +236,12 @@
goto iputfail;
}
unmap_buffer(bh);
- inode->i_nlink = inode->i_count = 1;
inode->i_dev = inode->i_sb->s_dev;
- inode->i_uid = current->euid;
inode->i_gid = (dir->i_mode & S_ISGID) ? dir->i_gid
: (__u8) current->egid;
inode->i_dirt = 1;
inode->i_ino = j;
inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
- inode->i_op = NULL;
#ifdef BLOAT_FS
inode->i_blocks = inode->i_blksize = 0;
diff -Nur elks.orig/fs/minix/inode.c elks/fs/minix/inode.c
--- elks.orig/fs/minix/inode.c 2014-11-25 15:56:48.000000000 -0600
+++ elks/fs/minix/inode.c 2014-11-26 14:42:12.000000000 -0600
@@ -301,15 +301,15 @@
static unsigned short map_izone(register struct inode *inode, block_t block,
int create)
{
- register unsigned short *i_zone = inode->i_zone;
+ register __u16 *i_zone = &(inode->i_zone[block]);
- if (create && !i_zone[block]) {
- if ((i_zone[block] = minix_new_block(inode->i_sb))) {
+ if (create && !(*i_zone)) {
+ if ((*i_zone = minix_new_block(inode->i_sb))) {
inode->i_ctime = CURRENT_TIME;
inode->i_dirt = 1;
}
}
- return i_zone[block];
+ return *i_zone;
}
static unsigned short map_iblock(register struct inode *inode, block_t i,
diff -Nur elks.orig/fs/minix/namei.c elks/fs/minix/namei.c
--- elks.orig/fs/minix/namei.c 2014-11-25 15:48:47.000000000 -0600
+++ elks/fs/minix/namei.c 2014-11-26 15:14:07.000000000 -0600
@@ -215,9 +215,9 @@
dir->i_mtime = dir->i_ctime = CURRENT_TIME;
dir->i_dirt = 1;
- for (i = 0; i < info->s_namelen; i++)
- de->name[i] = (i < namelen) ? (char) get_user_char(name + i)
- : '\0';
+ memcpy_fromfs(de->name, name, namelen);
+ if((i = info->s_namelen - namelen) > 0)
+ memset(de->name + namelen, 0, i);
#ifdef BLOAT_FS
dir->i_version = ++event;
@@ -250,14 +250,11 @@
*result = NULL;
if (!dir)
return -ENOENT;
- inode = minix_new_inode(dir);
+ inode = minix_new_inode(dir, (__u16)mode);
if (!inode) {
iput(dir);
return -ENOSPC;
}
- inode->i_op = &minix_file_inode_operations;
- inode->i_mode = (__u16) mode;
- inode->i_dirt = 1;
error = minix_add_entry(dir, name, len, &bh, &de);
if (error) {
inode->i_nlink--;
@@ -290,24 +287,16 @@
iput(dir);
return -EEXIST;
}
- inode = minix_new_inode(dir);
+
+ inode = minix_new_inode(dir, (__u16)mode);
if (!inode) {
iput(dir);
return -ENOSPC;
}
- inode->i_uid = current->euid;
- inode->i_mode = (__u16) mode;
- inode->i_op = NULL;
-
- minix_set_ops(inode);
-
- if (S_ISDIR(inode->i_mode))
- if (dir->i_mode & S_ISGID)
- inode->i_mode |= S_ISGID;
if (S_ISBLK(mode) || S_ISCHR(mode))
inode->i_rdev = to_kdev_t(rdev);
- inode->i_dirt = 1;
+
error = minix_add_entry(dir, name, len, &bh, &de);
#if 1
if (error) {
@@ -360,20 +349,19 @@
iput(dir);
return -EMLINK;
}
- inode = minix_new_inode(dir);
+
+ inode = minix_new_inode(dir, (__u16)(S_IFDIR|(mode & 0777 & ~current->fs.umask)));
if (!inode) {
iput(dir);
return -ENOSPC;
}
debug("m_mkdir: new_inode succeeded\n");
- inode->i_op = &minix_dir_inode_operations;
inode->i_size = 2 * dir->i_sb->u.minix_sb.s_dirsize;
debug("m_mkdir: starting minix_bread\n");
dir_block = minix_bread(inode, 0, 1);
if (!dir_block) {
iput(dir);
inode->i_nlink--;
- inode->i_dirt = 1;
iput(inode);
return -ENOSPC;
}
@@ -391,10 +379,6 @@
mark_buffer_dirty(dir_block, 1);
unmap_brelse(dir_block);
debug("m_mkdir: dir_block update succeeded\n");
- inode->i_mode = S_IFDIR | (mode & 0777 & ~current->fs.umask);
- if (dir->i_mode & S_ISGID)
- inode->i_mode |= S_ISGID;
- inode->i_dirt = 1;
error = minix_add_entry(dir, name, len, &bh, &de);
if (error) {
iput(dir);
@@ -543,25 +527,24 @@
struct buffer_head *bh;
struct minix_dir_entry *de;
- repeat:
- retval = -ENOENT;
- inode = NULL;
- bh = minix_find_entry(dir, name, len, &de);
- if (!bh)
- goto end_unlink;
- map_buffer(bh);
- if (!(inode = iget(dir->i_sb, (ino_t) de->inode)))
- goto end_unlink;
- retval = -EPERM;
- if (S_ISDIR(inode->i_mode))
- goto end_unlink;
- if (de->inode != inode->i_ino) {
+ goto init_loop;
+ do {
iput(inode);
unmap_brelse(bh);
-
schedule();
- goto repeat;
- }
+ init_loop:
+ retval = -ENOENT;
+ inode = NULL;
+ bh = minix_find_entry(dir, name, len, &de);
+ if (!bh)
+ goto end_unlink;
+ map_buffer(bh);
+ if (!(inode = iget(dir->i_sb, (ino_t) de->inode)))
+ goto end_unlink;
+ retval = -EPERM;
+ if (S_ISDIR(inode->i_mode))
+ goto end_unlink;
+ } while(de->inode != inode->i_ino);
if ((dir->i_mode & S_ISVTX) && !suser() &&
current->euid != inode->i_uid && current->euid != dir->i_uid)
goto end_unlink;
@@ -603,17 +586,14 @@
register struct buffer_head *name_block;
int i;
- if (!(inode = minix_new_inode(dir))) {
+ if (!(inode = minix_new_inode(dir, S_IFLNK | 0777))) {
iput(dir);
return -ENOSPC;
}
- inode->i_mode = (__u16) (S_IFLNK | 0777);
- inode->i_op = &minix_symlink_inode_operations;
name_block = minix_bread(inode, 0, 1);
if (!name_block) {
iput(dir);
inode->i_nlink--;
- inode->i_dirt = 1;
iput(inode);
return -ENOSPC;
}
@@ -625,19 +605,16 @@
inode->i_size = (__u32) i;
mark_buffer_dirty(name_block, 1);
unmap_brelse(name_block);
- inode->i_dirt = 1;
bh = minix_find_entry(dir, name, len, &de);
map_buffer(bh);
if (bh) {
- inode->i_nlink--;
- inode->i_dirt = 1;
- iput(inode);
unmap_brelse(bh);
- iput(dir);
- return -EEXIST;
+ i = -EEXIST;
+ goto err_symlink;
}
i = minix_add_entry(dir, name, len, &bh, &de);
if (i) {
+ err_symlink:
inode->i_nlink--;
inode->i_dirt = 1;
iput(inode);
diff -Nur elks.orig/include/linuxmt/minix_fs.h elks/include/linuxmt/minix_fs.h
--- elks.orig/include/linuxmt/minix_fs.h 2014-11-16 08:20:56.000000000 -0600
+++ elks/include/linuxmt/minix_fs.h 2014-11-26 13:44:30.000000000 -0600
@@ -86,7 +86,7 @@
extern int minix_mkdir(register struct inode *,char *,size_t,int);
extern int minix_mknod(register struct inode *,char *,size_t,int,int);
extern block_t minix_new_block(register struct super_block *);
-extern struct inode *minix_new_inode(struct inode *);
+extern struct inode *minix_new_inode(struct inode *,__u16);
extern void minix_put_inode(register struct inode *);
extern void minix_put_super(register struct super_block *);
/*extern void minix_read_inode(register struct inode *);*/
diff -Nur elks.orig/net/socket.c elks/net/socket.c
--- elks.orig/net/socket.c 2014-11-16 08:20:56.000000000 -0600
+++ elks/net/socket.c 2014-11-26 14:20:21.000000000 -0600
@@ -103,9 +103,8 @@
return NULL;
inode->i_mode = S_IFSOCK;
+ inode->i_gid = (__u8) current->egid;
inode->i_sock = 1;
- inode->i_uid = current->uid;
- inode->i_gid = (__u8) current->gid;
sock = &inode->u.socket_i;
sock->state = SS_UNCONNECTED;
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Simplification of inode initialization
2014-11-26 23:09 [PATCH] Simplification of inode initialization Juan Perez-Sanchez
@ 2014-11-27 16:51 ` Jody Bruchon
0 siblings, 0 replies; 2+ messages in thread
From: Jody Bruchon @ 2014-11-27 16:51 UTC (permalink / raw)
To: linux-8086
Both patches applied!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-11-27 16:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-26 23:09 [PATCH] Simplification of inode initialization Juan Perez-Sanchez
2014-11-27 16:51 ` Jody Bruchon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox