uclinux-2008R1-RC8(bf561)到VDSP5的移植(47):d_alloc引出的问题

在内核中有一个d_alloc函数,用于分配一个dentry的结构体并进行初始化。

/**
 * d_alloc    -    allocate a dcache entry
 * @parent: parent of entry to allocate
 * @name: qstr of the name
 *
 * Allocates a dentry. It returns %NULL if there is insufficient memory
 * available. On a success the dentry is returned. The name passed in is
 * copied and the copy passed in may be reused after this call.
 */

struct dentry *d_alloc(struct dentry * parent, const struct qstr *name)
{
     struct dentry *dentry;
     char *dname;

     dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
     if (!dentry)
         return NULL;

     if (name->len > DNAME_INLINE_LEN-1) {
         dname = kmalloc(name->len + 1, GFP_KERNEL);
         if (!dname) {
              kmem_cache_free(dentry_cache, dentry);
              return NULL;
         }
     } else {
         dname = dentry->d_iname;
     }  
     dentry->d_name.name = dname;

     dentry->d_name.len = name->len;
     dentry->d_name.hash = name->hash;
     memcpy(dname, name->name, name->len);
     dname[name->len] = 0;

     dentry->d_count.lock = 0; // 新加的语句
     atomic_set(&dentry->d_count, 1);
     dentry->d_flags = DCACHE_UNHASHED;
     spin_lock_init(&dentry->d_lock);
     dentry->d_inode = NULL;
     dentry->d_parent = NULL;
     dentry->d_sb = NULL;
     dentry->d_op = NULL;
     dentry->d_fsdata = NULL;
     dentry->d_mounted = 0;
#ifdef CONFIG_PROFILING
     dentry->d_cookie = NULL;
#endif
     INIT_HLIST_NODE(&dentry->d_hash);
     INIT_LIST_HEAD(&dentry->d_lru);
     INIT_LIST_HEAD(&dentry->d_subdirs);
     INIT_LIST_HEAD(&dentry->d_alias);

     if (parent) {
         dentry->d_parent = dget(parent);
         dentry->d_sb = parent->d_sb;
     } else {
         INIT_LIST_HEAD(&dentry->d_u.d_child);
     }

     spin_lock(&dcache_lock);
     if (parent)
         list_add(&dentry->d_u.d_child, &parent->d_subdirs);
     dentry_stat.nr_dentry++;
     spin_unlock(&dcache_lock);

     return dentry;
}

时间: 2024-09-20 00:14:35

uclinux-2008R1-RC8(bf561)到VDSP5的移植(47):d_alloc引出的问题的相关文章

uclinux-2008R1-RC8(bf561)到VDSP5的移植(62)

uclinux-2008R1-RC8(bf561)到VDSP5的移植(62):Failed to open '#include' file 'bf561.h' 在include/asm/mach/blackfin.h文件中,有这样的语句: #include "bf561.h" #include "mem_map.h" #include "defBF561.h" #include "anomaly.h" 当在asm文件中包含这个

uclinux-2008R1-RC8(bf561)到VDSP5的移植(58)

uclinux-2008R1-RC8(bf561)到VDSP5的移植(58): unable to open an initial console blog. 碰到一个郁闷的问题,提示" unable to open an initial console"后再没有下文了. 搜了下这个错误出现的位置,在init_post函数中: if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)

uclinux-2008R1-RC8(bf561)到VDSP5的移植(57)

clinux-2008R1-RC8(bf561)到VDSP5的移植(57):_NSIG_WORDS_is_unsupported_size 在include/linux/signal.h中使用了一个函数_NSIG_WORDS_is_unsupported_size,其使用过程大致如下所示: static inline int sigisemptyset(sigset_t *set) { extern void _NSIG_WORDS_is_unsupported_size(void); swit

uclinux-2008R1-RC8(bf561)到VDSP5的移植(43)

uclinux-2008R1-RC8(bf561)到VDSP5的移植(43):__builtin_return_address的问题 __builtin_return_address (LEVEL):这是GCC的内建函数,用于返回当前函数或其调用者的返回地址,参数LEVEL 指定在栈上搜索框架的个数,0 表示当前函数的返回地址,1 表示当前函数的调用者的返回地址,依此类推.在VDSP中,通过FP的循环取值可以完成相似的功能(参见以前的文章<使用FP取得函数的调用堆栈>).查了下内核对此函数的使

uclinux-2008R1-RC8(bf561)到VDSP5的移植(24):CONFIG_NR_CPUS

uclinux内核将bf561的每一个核都视为一个独立的CPU,因此在config.h中补上定义: // 多核支持 #define CONFIG_SMP 1 #define CONFIG_NR_CPUS 2

uclinux-2008R1-RC8(bf561)到VDSP5的移植(1):前言

1 目标 将uclinux-2008R1-RC8(bf561)移植到VDSP5上. 让uclinux支持双核. 2 原则 1.首先注释掉所有的声明和实现,但是保留#include和#define这样的语句. 2.逐步添加所需要的功能. 3.smp相关的部分参考linux-2.6.19的内核. 4.使用VDSP库.

uclinux-2008R1-RC8(bf561)到VDSP5的移植(3):Head.s

uclinux系统的入口点为head.s,因此先将此文件添加到corea.dlb,先改下语法错误. 1 时钟配置 因为没有使用引导程序,因此在内核启动时需要重新配置CPU的运行速度.在config.h中添加以下定义: // 时钟配置 #define CONFIG_CLKIN_HZ 27000000 // 晶振频率 #define CONFIG_VCO_MULT 22 // 内核倍频 #define CONFIG_CCLK_DIV 1 // 内核分频 #define CONFIG_SCLK_DIV

uclinux-2008R1-RC8(bf561)到VDSP5的移植(37):_cplb_mgr

在uclinux内核中,提供了一个函数:_cplb_mgr,此函数位于 arch/blackfin/kernel/cpu-nompu/cplbmgr.s,它的作用是当bf561发生cplb miss exception的时候替换掉最后的cache范围.在vdsp5中同样提供了一个_cplb_mgr的函数,而且VDSP在默认情况下会使用自己的库中的函数,从而造成内核错误. 因此,我们需要在config.h中增加一个定义: #define _cplb_mgr _uclinux_cplb_mgr #d

uclinux-2008R1-RC8(bf561)到VDSP5的移植(2):代码注释

因为uclinux内核是个庞然大物,为避免一开始就遭受打击,所以就决定先将所有的代码注释掉.但是与此同时要保留各个文件之间的依赖关系,因此必须保留#include这样的语句.再考虑到uclinux是通过宏定义来控制各种功能实现的,且宏定义几乎不会对移植造成任何困扰,所以也保留了#if #define这样的语句. 以下就是自己写的一小段代码,用于实现上述功能,在VS2005下可以使用. // hprocess.cpp : 定义控制台应用程序的入口点.//#include "stdafx.h&quo