perf hist: fix objdump output parsing
[safe/jmp/linux-2.6] / fs / reiserfs / namei.c
index 16e9cff..ee78d4a 100644 (file)
 
 #include <linux/time.h>
 #include <linux/bitops.h>
+#include <linux/slab.h>
 #include <linux/reiserfs_fs.h>
 #include <linux/reiserfs_acl.h>
 #include <linux/reiserfs_xattr.h>
-#include <linux/smp_lock.h>
 #include <linux/quotaops.h>
 
 #define INC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) { inc_nlink(i); if (i->i_nlink >= REISERFS_LINK_MAX) i->i_nlink=1; }
@@ -54,7 +54,7 @@ static int bin_search_in_dir_item(struct reiserfs_dir_entry *de, loff_t off)
 
 // comment?  maybe something like set de to point to what the path points to?
 static inline void set_de_item_location(struct reiserfs_dir_entry *de,
-                                       struct path *path)
+                                       struct treepath *path)
 {
        de->de_bh = get_last_bh(path);
        de->de_ih = get_ih(path);
@@ -67,8 +67,7 @@ inline void set_de_name_and_namelen(struct reiserfs_dir_entry *de)
 {
        struct reiserfs_de_head *deh = de->de_deh + de->de_entry_num;
 
-       if (de->de_entry_num >= ih_entry_count(de->de_ih))
-               BUG();
+       BUG_ON(de->de_entry_num >= ih_entry_count(de->de_ih));
 
        de->de_entrylen = entry_length(de->de_bh, de->de_ih, de->de_entry_num);
        de->de_namelen = de->de_entrylen - (de_with_sd(deh) ? SD_SIZE : 0);
@@ -80,8 +79,7 @@ inline void set_de_name_and_namelen(struct reiserfs_dir_entry *de)
 // what entry points to
 static inline void set_de_object_key(struct reiserfs_dir_entry *de)
 {
-       if (de->de_entry_num >= ih_entry_count(de->de_ih))
-               BUG();
+       BUG_ON(de->de_entry_num >= ih_entry_count(de->de_ih));
        de->de_dir_id = deh_dir_id(&(de->de_deh[de->de_entry_num]));
        de->de_objectid = deh_objectid(&(de->de_deh[de->de_entry_num]));
 }
@@ -90,8 +88,7 @@ static inline void store_de_entry_key(struct reiserfs_dir_entry *de)
 {
        struct reiserfs_de_head *deh = de->de_deh + de->de_entry_num;
 
-       if (de->de_entry_num >= ih_entry_count(de->de_ih))
-               BUG();
+       BUG_ON(de->de_entry_num >= ih_entry_count(de->de_ih));
 
        /* store key of the found entry */
        de->de_entry_key.version = KEY_FORMAT_3_5;
@@ -110,13 +107,13 @@ key of the first directory entry in it.
 This function first calls search_by_key, then, if item whose first
 entry matches is not found it looks for the entry inside directory
 item found by search_by_key. Fills the path to the entry, and to the
-entry position in the item 
+entry position in the item
 
 */
 
 /* The function is NOT SCHEDULE-SAFE! */
 int search_by_entry_key(struct super_block *sb, const struct cpu_key *key,
-                       struct path *path, struct reiserfs_dir_entry *de)
+                       struct treepath *path, struct reiserfs_dir_entry *de)
 {
        int retval;
 
@@ -124,8 +121,8 @@ int search_by_entry_key(struct super_block *sb, const struct cpu_key *key,
        switch (retval) {
        case ITEM_NOT_FOUND:
                if (!PATH_LAST_POSITION(path)) {
-                       reiserfs_warning(sb,
-                                        "vs-7000: search_by_entry_key: search_by_key returned item position == 0");
+                       reiserfs_error(sb, "vs-7000", "search_by_key "
+                                      "returned item position == 0");
                        pathrelse(path);
                        return IO_ERROR;
                }
@@ -139,8 +136,7 @@ int search_by_entry_key(struct super_block *sb, const struct cpu_key *key,
 
        default:
                pathrelse(path);
-               reiserfs_warning(sb,
-                                "vs-7002: search_by_entry_key: no path to here");
+               reiserfs_error(sb, "vs-7002", "no path to here");
                return IO_ERROR;
        }
 
@@ -150,10 +146,9 @@ int search_by_entry_key(struct super_block *sb, const struct cpu_key *key,
        if (!is_direntry_le_ih(de->de_ih) ||
            COMP_SHORT_KEYS(&(de->de_ih->ih_key), key)) {
                print_block(de->de_bh, 0, -1, -1);
-               reiserfs_panic(sb,
-                              "vs-7005: search_by_entry_key: found item %h is not directory item or "
-                              "does not belong to the same directory as key %K",
-                              de->de_ih, key);
+               reiserfs_panic(sb, "vs-7005", "found item %h is not directory "
+                              "item or does not belong to the same directory "
+                              "as key %K", de->de_ih, key);
        }
 #endif                         /* CONFIG_REISERFS_CHECK */
 
@@ -285,7 +280,7 @@ static int linear_search_in_dir_item(struct cpu_key *key,
 // may return NAME_FOUND, NAME_FOUND_INVISIBLE, NAME_NOT_FOUND
 // FIXME: should add something like IOERROR
 static int reiserfs_find_entry(struct inode *dir, const char *name, int namelen,
-                              struct path *path_to_entry,
+                              struct treepath *path_to_entry,
                               struct reiserfs_dir_entry *de)
 {
        struct cpu_key key_to_search;
@@ -304,8 +299,7 @@ static int reiserfs_find_entry(struct inode *dir, const char *name, int namelen,
                    search_by_entry_key(dir->i_sb, &key_to_search,
                                        path_to_entry, de);
                if (retval == IO_ERROR) {
-                       reiserfs_warning(dir->i_sb, "zam-7001: io error in %s",
-                                        __FUNCTION__);
+                       reiserfs_error(dir->i_sb, "zam-7001", "io error");
                        return IO_ERROR;
                }
 
@@ -331,6 +325,7 @@ static struct dentry *reiserfs_lookup(struct inode *dir, struct dentry *dentry,
                                      struct nameidata *nd)
 {
        int retval;
+       int lock_depth;
        struct inode *inode = NULL;
        struct reiserfs_dir_entry de;
        INITIALIZE_PATH(path_to_entry);
@@ -338,38 +333,32 @@ static struct dentry *reiserfs_lookup(struct inode *dir, struct dentry *dentry,
        if (REISERFS_MAX_NAME(dir->i_sb->s_blocksize) < dentry->d_name.len)
                return ERR_PTR(-ENAMETOOLONG);
 
-       reiserfs_write_lock(dir->i_sb);
+       /*
+        * Might be called with or without the write lock, must be careful
+        * to not recursively hold it in case we want to release the lock
+        * before rescheduling.
+        */
+       lock_depth = reiserfs_write_lock_once(dir->i_sb);
+
        de.de_gen_number_bit_string = NULL;
        retval =
            reiserfs_find_entry(dir, dentry->d_name.name, dentry->d_name.len,
                                &path_to_entry, &de);
        pathrelse(&path_to_entry);
        if (retval == NAME_FOUND) {
-               /* Hide the .reiserfs_priv directory */
-               if (reiserfs_xattrs(dir->i_sb) &&
-                   !old_format_only(dir->i_sb) &&
-                   REISERFS_SB(dir->i_sb)->priv_root &&
-                   REISERFS_SB(dir->i_sb)->priv_root->d_inode &&
-                   de.de_objectid ==
-                   le32_to_cpu(INODE_PKEY
-                               (REISERFS_SB(dir->i_sb)->priv_root->d_inode)->
-                               k_objectid)) {
-                       reiserfs_write_unlock(dir->i_sb);
-                       return ERR_PTR(-EACCES);
-               }
-
-               inode =
-                   reiserfs_iget(dir->i_sb, (struct cpu_key *)&(de.de_dir_id));
+               inode = reiserfs_iget(dir->i_sb,
+                                     (struct cpu_key *)&(de.de_dir_id));
                if (!inode || IS_ERR(inode)) {
-                       reiserfs_write_unlock(dir->i_sb);
+                       reiserfs_write_unlock_once(dir->i_sb, lock_depth);
                        return ERR_PTR(-EACCES);
                }
 
-               /* Propogate the priv_object flag so we know we're in the priv tree */
-               if (is_reiserfs_priv_object(dir))
-                       reiserfs_mark_inode_private(inode);
+               /* Propagate the private flag so we know we're
+                * in the priv tree */
+               if (IS_PRIVATE(dir))
+                       inode->i_flags |= S_PRIVATE;
        }
-       reiserfs_write_unlock(dir->i_sb);
+       reiserfs_write_unlock_once(dir->i_sb, lock_depth);
        if (retval == IO_ERROR) {
                return ERR_PTR(-EIO);
        }
@@ -377,7 +366,7 @@ static struct dentry *reiserfs_lookup(struct inode *dir, struct dentry *dentry,
        return d_splice_alias(inode, dentry);
 }
 
-/* 
+/*
 ** looks up the dentry of the parent directory for child.
 ** taken from ext2_get_parent
 */
@@ -387,7 +376,6 @@ struct dentry *reiserfs_get_parent(struct dentry *child)
        struct inode *inode = NULL;
        struct reiserfs_dir_entry de;
        INITIALIZE_PATH(path_to_entry);
-       struct dentry *parent;
        struct inode *dir = child->d_inode;
 
        if (dir->i_nlink == 0) {
@@ -405,18 +393,10 @@ struct dentry *reiserfs_get_parent(struct dentry *child)
        inode = reiserfs_iget(dir->i_sb, (struct cpu_key *)&(de.de_dir_id));
        reiserfs_write_unlock(dir->i_sb);
 
-       if (!inode || IS_ERR(inode)) {
-               return ERR_PTR(-EACCES);
-       }
-       parent = d_alloc_anon(inode);
-       if (!parent) {
-               iput(inode);
-               parent = ERR_PTR(-ENOMEM);
-       }
-       return parent;
+       return d_obtain_alias(inode);
 }
 
-/* add entry to the directory (entry can be hidden). 
+/* add entry to the directory (entry can be hidden).
 
 insert definition of when hidden directories are used here -Hans
 
@@ -456,7 +436,7 @@ static int reiserfs_add_entry(struct reiserfs_transaction_handle *th,
        buflen = DEH_SIZE + ROUND_UP(namelen);
        if (buflen > sizeof(small_buf)) {
                buffer = kmalloc(buflen, GFP_NOFS);
-               if (buffer == 0)
+               if (!buffer)
                        return -ENOMEM;
        } else
                buffer = small_buf;
@@ -497,10 +477,9 @@ static int reiserfs_add_entry(struct reiserfs_transaction_handle *th,
                }
 
                if (retval != NAME_FOUND) {
-                       reiserfs_warning(dir->i_sb,
-                                        "zam-7002:%s: \"reiserfs_find_entry\" "
-                                        "has returned unexpected value (%d)",
-                                        __FUNCTION__, retval);
+                       reiserfs_error(dir->i_sb, "zam-7002",
+                                      "reiserfs_find_entry() returned "
+                                      "unexpected value (%d)", retval);
                }
 
                return -EEXIST;
@@ -511,8 +490,9 @@ static int reiserfs_add_entry(struct reiserfs_transaction_handle *th,
                                MAX_GENERATION_NUMBER + 1);
        if (gen_number > MAX_GENERATION_NUMBER) {
                /* there is no free generation number */
-               reiserfs_warning(dir->i_sb,
-                                "reiserfs_add_entry: Congratulations! we have got hash function screwed up");
+               reiserfs_warning(dir->i_sb, "reiserfs-7010",
+                                "Congratulations! we have got hash function "
+                                "screwed up");
                if (buffer != small_buf)
                        kfree(buffer);
                pathrelse(&path);
@@ -528,10 +508,9 @@ static int reiserfs_add_entry(struct reiserfs_transaction_handle *th,
        if (gen_number != 0) {  /* we need to re-search for the insertion point */
                if (search_by_entry_key(dir->i_sb, &entry_key, &path, &de) !=
                    NAME_NOT_FOUND) {
-                       reiserfs_warning(dir->i_sb,
-                                        "vs-7032: reiserfs_add_entry: "
-                                        "entry with this key (%K) already exists",
-                                        &entry_key);
+                       reiserfs_warning(dir->i_sb, "vs-7032",
+                                        "entry with this key (%K) already "
+                                        "exists", &entry_key);
 
                        if (buffer != small_buf)
                                kfree(buffer);
@@ -568,38 +547,28 @@ static int reiserfs_add_entry(struct reiserfs_transaction_handle *th,
 */
 static int drop_new_inode(struct inode *inode)
 {
-       DQUOT_DROP(inode);
+       dquot_drop(inode);
        make_bad_inode(inode);
        inode->i_flags |= S_NOQUOTA;
        iput(inode);
        return 0;
 }
 
-/* utility function that does setup for reiserfs_new_inode.  
-** DQUOT_INIT needs lots of credits so it's better to have it
+/* utility function that does setup for reiserfs_new_inode.
+** dquot_initialize needs lots of credits so it's better to have it
 ** outside of a transaction, so we had to pull some bits of
 ** reiserfs_new_inode out into this func.
 */
 static int new_inode_init(struct inode *inode, struct inode *dir, int mode)
 {
-
-       /* the quota init calls have to know who to charge the quota to, so
-        ** we have to set uid and gid here
-        */
-       inode->i_uid = current->fsuid;
-       inode->i_mode = mode;
        /* Make inode invalid - just in case we are going to drop it before
         * the initialization happens */
        INODE_PKEY(inode)->k_objectid = 0;
-
-       if (dir->i_mode & S_ISGID) {
-               inode->i_gid = dir->i_gid;
-               if (S_ISDIR(mode))
-                       inode->i_mode |= S_ISGID;
-       } else {
-               inode->i_gid = current->fsgid;
-       }
-       DQUOT_INIT(inode);
+       /* the quota init calls have to know who to charge the quota to, so
+        ** we have to set uid and gid here
+        */
+       inode_init_owner(inode, dir, mode);
+       dquot_initialize(inode);
        return 0;
 }
 
@@ -614,20 +583,24 @@ static int reiserfs_create(struct inode *dir, struct dentry *dentry, int mode,
            2 * (REISERFS_QUOTA_INIT_BLOCKS(dir->i_sb) +
                 REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb));
        struct reiserfs_transaction_handle th;
-       int locked;
+       struct reiserfs_security_handle security;
+
+       dquot_initialize(dir);
 
        if (!(inode = new_inode(dir->i_sb))) {
                return -ENOMEM;
        }
        new_inode_init(inode, dir, mode);
 
-       locked = reiserfs_cache_default_acl(dir);
-
+       jbegin_count += reiserfs_cache_default_acl(dir);
+       retval = reiserfs_security_init(dir, inode, &security);
+       if (retval < 0) {
+               drop_new_inode(inode);
+               return retval;
+       }
+       jbegin_count += retval;
        reiserfs_write_lock(dir->i_sb);
 
-       if (locked)
-               reiserfs_write_lock_xattrs(dir->i_sb);
-
        retval = journal_begin(&th, dir->i_sb, jbegin_count);
        if (retval) {
                drop_new_inode(inode);
@@ -636,15 +609,10 @@ static int reiserfs_create(struct inode *dir, struct dentry *dentry, int mode,
 
        retval =
            reiserfs_new_inode(&th, dir, mode, NULL, 0 /*i_size */ , dentry,
-                              inode);
+                              inode, &security);
        if (retval)
                goto out_failed;
 
-       if (locked) {
-               reiserfs_write_unlock_xattrs(dir->i_sb);
-               locked = 0;
-       }
-
        inode->i_op = &reiserfs_file_inode_operations;
        inode->i_fop = &reiserfs_file_operations;
        inode->i_mapping->a_ops = &reiserfs_address_space_operations;
@@ -659,6 +627,7 @@ static int reiserfs_create(struct inode *dir, struct dentry *dentry, int mode,
                err = journal_end(&th, dir->i_sb, jbegin_count);
                if (err)
                        retval = err;
+               unlock_new_inode(inode);
                iput(inode);
                goto out_failed;
        }
@@ -666,11 +635,10 @@ static int reiserfs_create(struct inode *dir, struct dentry *dentry, int mode,
        reiserfs_update_inode_transaction(dir);
 
        d_instantiate(dentry, inode);
+       unlock_new_inode(inode);
        retval = journal_end(&th, dir->i_sb, jbegin_count);
 
       out_failed:
-       if (locked)
-               reiserfs_write_unlock_xattrs(dir->i_sb);
        reiserfs_write_unlock(dir->i_sb);
        return retval;
 }
@@ -681,28 +649,32 @@ static int reiserfs_mknod(struct inode *dir, struct dentry *dentry, int mode,
        int retval;
        struct inode *inode;
        struct reiserfs_transaction_handle th;
+       struct reiserfs_security_handle security;
        /* We need blocks for transaction + (user+group)*(quotas for new inode + update of quota for directory owner) */
        int jbegin_count =
            JOURNAL_PER_BALANCE_CNT * 3 +
            2 * (REISERFS_QUOTA_INIT_BLOCKS(dir->i_sb) +
                 REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb));
-       int locked;
 
        if (!new_valid_dev(rdev))
                return -EINVAL;
 
+       dquot_initialize(dir);
+
        if (!(inode = new_inode(dir->i_sb))) {
                return -ENOMEM;
        }
        new_inode_init(inode, dir, mode);
 
-       locked = reiserfs_cache_default_acl(dir);
-
+       jbegin_count += reiserfs_cache_default_acl(dir);
+       retval = reiserfs_security_init(dir, inode, &security);
+       if (retval < 0) {
+               drop_new_inode(inode);
+               return retval;
+       }
+       jbegin_count += retval;
        reiserfs_write_lock(dir->i_sb);
 
-       if (locked)
-               reiserfs_write_lock_xattrs(dir->i_sb);
-
        retval = journal_begin(&th, dir->i_sb, jbegin_count);
        if (retval) {
                drop_new_inode(inode);
@@ -711,16 +683,11 @@ static int reiserfs_mknod(struct inode *dir, struct dentry *dentry, int mode,
 
        retval =
            reiserfs_new_inode(&th, dir, mode, NULL, 0 /*i_size */ , dentry,
-                              inode);
+                              inode, &security);
        if (retval) {
                goto out_failed;
        }
 
-       if (locked) {
-               reiserfs_write_unlock_xattrs(dir->i_sb);
-               locked = 0;
-       }
-
        inode->i_op = &reiserfs_special_inode_operations;
        init_special_inode(inode, inode->i_mode, rdev);
 
@@ -740,16 +707,16 @@ static int reiserfs_mknod(struct inode *dir, struct dentry *dentry, int mode,
                err = journal_end(&th, dir->i_sb, jbegin_count);
                if (err)
                        retval = err;
+               unlock_new_inode(inode);
                iput(inode);
                goto out_failed;
        }
 
        d_instantiate(dentry, inode);
+       unlock_new_inode(inode);
        retval = journal_end(&th, dir->i_sb, jbegin_count);
 
       out_failed:
-       if (locked)
-               reiserfs_write_unlock_xattrs(dir->i_sb);
        reiserfs_write_unlock(dir->i_sb);
        return retval;
 }
@@ -759,12 +726,15 @@ static int reiserfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
        int retval;
        struct inode *inode;
        struct reiserfs_transaction_handle th;
+       struct reiserfs_security_handle security;
+       int lock_depth;
        /* We need blocks for transaction + (user+group)*(quotas for new inode + update of quota for directory owner) */
        int jbegin_count =
            JOURNAL_PER_BALANCE_CNT * 3 +
            2 * (REISERFS_QUOTA_INIT_BLOCKS(dir->i_sb) +
                 REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb));
-       int locked;
+
+       dquot_initialize(dir);
 
 #ifdef DISPLACE_NEW_PACKING_LOCALITIES
        /* set flag that new packing locality created and new blocks for the content     * of that directory are not displaced yet */
@@ -776,11 +746,14 @@ static int reiserfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
        }
        new_inode_init(inode, dir, mode);
 
-       locked = reiserfs_cache_default_acl(dir);
-
-       reiserfs_write_lock(dir->i_sb);
-       if (locked)
-               reiserfs_write_lock_xattrs(dir->i_sb);
+       jbegin_count += reiserfs_cache_default_acl(dir);
+       retval = reiserfs_security_init(dir, inode, &security);
+       if (retval < 0) {
+               drop_new_inode(inode);
+               return retval;
+       }
+       jbegin_count += retval;
+       lock_depth = reiserfs_write_lock_once(dir->i_sb);
 
        retval = journal_begin(&th, dir->i_sb, jbegin_count);
        if (retval) {
@@ -796,17 +769,12 @@ static int reiserfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
            retval = reiserfs_new_inode(&th, dir, mode, NULL /*symlink */ ,
                                        old_format_only(dir->i_sb) ?
                                        EMPTY_DIR_SIZE_V1 : EMPTY_DIR_SIZE,
-                                       dentry, inode);
+                                       dentry, inode, &security);
        if (retval) {
                dir->i_nlink--;
                goto out_failed;
        }
 
-       if (locked) {
-               reiserfs_write_unlock_xattrs(dir->i_sb);
-               locked = 0;
-       }
-
        reiserfs_update_inode_transaction(inode);
        reiserfs_update_inode_transaction(dir);
 
@@ -825,6 +793,7 @@ static int reiserfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
                err = journal_end(&th, dir->i_sb, jbegin_count);
                if (err)
                        retval = err;
+               unlock_new_inode(inode);
                iput(inode);
                goto out_failed;
        }
@@ -832,11 +801,10 @@ static int reiserfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
        reiserfs_update_sd(&th, dir);
 
        d_instantiate(dentry, inode);
+       unlock_new_inode(inode);
        retval = journal_end(&th, dir->i_sb, jbegin_count);
-      out_failed:
-       if (locked)
-               reiserfs_write_unlock_xattrs(dir->i_sb);
-       reiserfs_write_unlock(dir->i_sb);
+out_failed:
+       reiserfs_write_unlock_once(dir->i_sb, lock_depth);
        return retval;
 }
 
@@ -844,7 +812,7 @@ static inline int reiserfs_empty_dir(struct inode *inode)
 {
        /* we can cheat because an old format dir cannot have
         ** EMPTY_DIR_SIZE, and a new format dir cannot have
-        ** EMPTY_DIR_SIZE_V1.  So, if the inode is either size, 
+        ** EMPTY_DIR_SIZE_V1.  So, if the inode is either size,
         ** regardless of disk format version, the directory is empty.
         */
        if (inode->i_size != EMPTY_DIR_SIZE &&
@@ -871,6 +839,8 @@ static int reiserfs_rmdir(struct inode *dir, struct dentry *dentry)
            JOURNAL_PER_BALANCE_CNT * 2 + 2 +
            4 * REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb);
 
+       dquot_initialize(dir);
+
        reiserfs_write_lock(dir->i_sb);
        retval = journal_begin(&th, dir->i_sb, jbegin_count);
        if (retval)
@@ -910,8 +880,9 @@ static int reiserfs_rmdir(struct inode *dir, struct dentry *dentry)
                goto end_rmdir;
 
        if (inode->i_nlink != 2 && inode->i_nlink != 1)
-               reiserfs_warning(inode->i_sb, "%s: empty directory has nlink "
-                                "!= 2 (%d)", __FUNCTION__, inode->i_nlink);
+               reiserfs_error(inode->i_sb, "reiserfs-7040",
+                              "empty directory has nlink != 2 (%d)",
+                              inode->i_nlink);
 
        clear_nlink(inode);
        inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC;
@@ -949,6 +920,9 @@ static int reiserfs_unlink(struct inode *dir, struct dentry *dentry)
        struct reiserfs_transaction_handle th;
        int jbegin_count;
        unsigned long savelink;
+       int depth;
+
+       dquot_initialize(dir);
 
        inode = dentry->d_inode;
 
@@ -960,7 +934,7 @@ static int reiserfs_unlink(struct inode *dir, struct dentry *dentry)
            JOURNAL_PER_BALANCE_CNT * 2 + 2 +
            4 * REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb);
 
-       reiserfs_write_lock(dir->i_sb);
+       depth = reiserfs_write_lock_once(dir->i_sb);
        retval = journal_begin(&th, dir->i_sb, jbegin_count);
        if (retval)
                goto out_unlink;
@@ -987,10 +961,9 @@ static int reiserfs_unlink(struct inode *dir, struct dentry *dentry)
        }
 
        if (!inode->i_nlink) {
-               reiserfs_warning(inode->i_sb, "%s: deleting nonexistent file "
-                                "(%s:%lu), %d", __FUNCTION__,
-                                reiserfs_bdevname(inode->i_sb), inode->i_ino,
-                                inode->i_nlink);
+               reiserfs_warning(inode->i_sb, "reiserfs-7042",
+                                "deleting nonexistent file (%lu), %d",
+                                inode->i_ino, inode->i_nlink);
                inode->i_nlink = 1;
        }
 
@@ -1022,7 +995,7 @@ static int reiserfs_unlink(struct inode *dir, struct dentry *dentry)
 
        retval = journal_end(&th, dir->i_sb, jbegin_count);
        reiserfs_check_path(&path);
-       reiserfs_write_unlock(dir->i_sb);
+       reiserfs_write_unlock_once(dir->i_sb, depth);
        return retval;
 
       end_unlink:
@@ -1032,7 +1005,7 @@ static int reiserfs_unlink(struct inode *dir, struct dentry *dentry)
        if (err)
                retval = err;
       out_unlink:
-       reiserfs_write_unlock(dir->i_sb);
+       reiserfs_write_unlock_once(dir->i_sb, depth);
        return retval;
 }
 
@@ -1044,6 +1017,7 @@ static int reiserfs_symlink(struct inode *parent_dir,
        char *name;
        int item_len;
        struct reiserfs_transaction_handle th;
+       struct reiserfs_security_handle security;
        int mode = S_IFLNK | S_IRWXUGO;
        /* We need blocks for transaction + (user+group)*(quotas for new inode + update of quota for directory owner) */
        int jbegin_count =
@@ -1051,11 +1025,20 @@ static int reiserfs_symlink(struct inode *parent_dir,
            2 * (REISERFS_QUOTA_INIT_BLOCKS(parent_dir->i_sb) +
                 REISERFS_QUOTA_TRANS_BLOCKS(parent_dir->i_sb));
 
+       dquot_initialize(parent_dir);
+
        if (!(inode = new_inode(parent_dir->i_sb))) {
                return -ENOMEM;
        }
        new_inode_init(inode, parent_dir, mode);
 
+       retval = reiserfs_security_init(parent_dir, inode, &security);
+       if (retval < 0) {
+               drop_new_inode(inode);
+               return retval;
+       }
+       jbegin_count += retval;
+
        reiserfs_write_lock(parent_dir->i_sb);
        item_len = ROUND_UP(strlen(symname));
        if (item_len > MAX_DIRECT_ITEM_LEN(parent_dir->i_sb->s_blocksize)) {
@@ -1073,8 +1056,6 @@ static int reiserfs_symlink(struct inode *parent_dir,
        memcpy(name, symname, strlen(symname));
        padd_item(name, item_len, strlen(symname));
 
-       /* We would inherit the default ACL here, but symlinks don't get ACLs */
-
        retval = journal_begin(&th, parent_dir->i_sb, jbegin_count);
        if (retval) {
                drop_new_inode(inode);
@@ -1084,7 +1065,7 @@ static int reiserfs_symlink(struct inode *parent_dir,
 
        retval =
            reiserfs_new_inode(&th, parent_dir, mode, name, strlen(symname),
-                              dentry, inode);
+                              dentry, inode, &security);
        kfree(name);
        if (retval) {           /* reiserfs_new_inode iputs for us */
                goto out_failed;
@@ -1109,11 +1090,13 @@ static int reiserfs_symlink(struct inode *parent_dir,
                err = journal_end(&th, parent_dir->i_sb, jbegin_count);
                if (err)
                        retval = err;
+               unlock_new_inode(inode);
                iput(inode);
                goto out_failed;
        }
 
        d_instantiate(dentry, inode);
+       unlock_new_inode(inode);
        retval = journal_end(&th, parent_dir->i_sb, jbegin_count);
       out_failed:
        reiserfs_write_unlock(parent_dir->i_sb);
@@ -1131,6 +1114,8 @@ static int reiserfs_link(struct dentry *old_dentry, struct inode *dir,
            JOURNAL_PER_BALANCE_CNT * 3 +
            2 * REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb);
 
+       dquot_initialize(dir);
+
        reiserfs_write_lock(dir->i_sb);
        if (inode->i_nlink >= REISERFS_LINK_MAX) {
                //FIXME: sd_nlink is 32 bit for new files
@@ -1178,7 +1163,7 @@ static int reiserfs_link(struct dentry *old_dentry, struct inode *dir,
        return retval;
 }
 
-// de contains information pointing to an entry which 
+/* de contains information pointing to an entry which */
 static int de_still_valid(const char *name, int len,
                          struct reiserfs_dir_entry *de)
 {
@@ -1201,15 +1186,14 @@ static int entry_points_to_object(const char *name, int len,
 
        if (inode) {
                if (!de_visible(de->de_deh + de->de_entry_num))
-                       reiserfs_panic(NULL,
-                                      "vs-7042: entry_points_to_object: entry must be visible");
+                       reiserfs_panic(inode->i_sb, "vs-7042",
+                                      "entry must be visible");
                return (de->de_objectid == inode->i_ino) ? 1 : 0;
        }
 
        /* this must be added hidden entry */
        if (de_visible(de->de_deh + de->de_entry_num))
-               reiserfs_panic(NULL,
-                              "vs-7043: entry_points_to_object: entry must be visible");
+               reiserfs_panic(NULL, "vs-7043", "entry must be visible");
 
        return 1;
 }
@@ -1223,10 +1207,10 @@ static void set_ino_in_dir_entry(struct reiserfs_dir_entry *de,
        de->de_deh[de->de_entry_num].deh_objectid = key->k_objectid;
 }
 
-/* 
+/*
  * process, that is going to call fix_nodes/do_balance must hold only
  * one path. If it holds 2 or more, it can get into endless waiting in
- * get_empty_nodes or its clones 
+ * get_empty_nodes or its clones
  */
 static int reiserfs_rename(struct inode *old_dir, struct dentry *old_dentry,
                           struct inode *new_dir, struct dentry *new_dentry)
@@ -1256,6 +1240,9 @@ static int reiserfs_rename(struct inode *old_dir, struct dentry *old_dentry,
            JOURNAL_PER_BALANCE_CNT * 3 + 5 +
            4 * REISERFS_QUOTA_TRANS_BLOCKS(old_dir->i_sb);
 
+       dquot_initialize(old_dir);
+       dquot_initialize(new_dir);
+
        old_inode = old_dentry->d_inode;
        new_dentry_inode = new_dentry->d_inode;
 
@@ -1280,7 +1267,7 @@ static int reiserfs_rename(struct inode *old_dir, struct dentry *old_dentry,
 
        old_inode_mode = old_inode->i_mode;
        if (S_ISDIR(old_inode_mode)) {
-               // make sure, that directory being renamed has correct ".." 
+               // make sure, that directory being renamed has correct ".."
                // and that its new parent directory has not too many links
                // already
 
@@ -1291,8 +1278,8 @@ static int reiserfs_rename(struct inode *old_dir, struct dentry *old_dentry,
                        }
                }
 
-               /* directory is renamed, its parent directory will be changed, 
-                ** so find ".." entry 
+               /* directory is renamed, its parent directory will be changed,
+                ** so find ".." entry
                 */
                dot_dot_de.de_gen_number_bit_string = NULL;
                retval =
@@ -1323,8 +1310,8 @@ static int reiserfs_rename(struct inode *old_dir, struct dentry *old_dentry,
                               new_dentry->d_name.len, old_inode, 0);
        if (retval == -EEXIST) {
                if (!new_dentry_inode) {
-                       reiserfs_panic(old_dir->i_sb,
-                                      "vs-7050: new entry is found, new inode == 0\n");
+                       reiserfs_panic(old_dir->i_sb, "vs-7050",
+                                      "new entry is found, new inode == 0");
                }
        } else if (retval) {
                int err = journal_end(&th, old_dir->i_sb, jbegin_count);
@@ -1402,9 +1389,9 @@ static int reiserfs_rename(struct inode *old_dir, struct dentry *old_dentry,
                   this stuff, yes? Then, having
                   gathered everything into RAM we
                   should lock the buffers, yes?  -Hans */
-               /* probably.  our rename needs to hold more 
-                ** than one path at once.  The seals would 
-                ** have to be written to deal with multi-path 
+               /* probably.  our rename needs to hold more
+                ** than one path at once.  The seals would
+                ** have to be written to deal with multi-path
                 ** issues -chris
                 */
                /* sanity checking before doing the rename - avoid races many
@@ -1482,7 +1469,7 @@ static int reiserfs_rename(struct inode *old_dir, struct dentry *old_dentry,
        }
 
        if (S_ISDIR(old_inode_mode)) {
-               // adjust ".." of renamed directory 
+               /* adjust ".." of renamed directory */
                set_ino_in_dir_entry(&dot_dot_de, INODE_PKEY(new_dir));
                journal_mark_dirty(&th, new_dir->i_sb, dot_dot_de.de_bh);
 
@@ -1504,8 +1491,8 @@ static int reiserfs_rename(struct inode *old_dir, struct dentry *old_dentry,
        if (reiserfs_cut_from_item
            (&th, &old_entry_path, &(old_de.de_entry_key), old_dir, NULL,
             0) < 0)
-               reiserfs_warning(old_dir->i_sb,
-                                "vs-7060: reiserfs_rename: couldn't not cut old name. Fsck later?");
+               reiserfs_error(old_dir->i_sb, "vs-7060",
+                              "couldn't not cut old name. Fsck later?");
 
        old_dir->i_size -= DEH_SIZE + old_de.de_entrylen;
 
@@ -1528,7 +1515,7 @@ static int reiserfs_rename(struct inode *old_dir, struct dentry *old_dentry,
 /*
  * directories can handle most operations...
  */
-struct inode_operations reiserfs_dir_inode_operations = {
+const struct inode_operations reiserfs_dir_inode_operations = {
        //&reiserfs_dir_operations,   /* default_file_ops */
        .create = reiserfs_create,
        .lookup = reiserfs_lookup,
@@ -1551,7 +1538,7 @@ struct inode_operations reiserfs_dir_inode_operations = {
  * symlink operations.. same as page_symlink_inode_operations, with xattr
  * stuff added
  */
-struct inode_operations reiserfs_symlink_inode_operations = {
+const struct inode_operations reiserfs_symlink_inode_operations = {
        .readlink = generic_readlink,
        .follow_link = page_follow_link_light,
        .put_link = page_put_link,
@@ -1567,7 +1554,7 @@ struct inode_operations reiserfs_symlink_inode_operations = {
 /*
  * special file operations.. just xattr/acl stuff
  */
-struct inode_operations reiserfs_special_inode_operations = {
+const struct inode_operations reiserfs_special_inode_operations = {
        .setattr = reiserfs_setattr,
        .setxattr = reiserfs_setxattr,
        .getxattr = reiserfs_getxattr,