Getname flags
Retired DISLab
132 static struct filename * 133 getname_flags(const char __user *filename, int flags, int *empty) 134 { 135 struct filename *result, *err; 136 int len; 137 long max; 138 char *kname; 139 140 result = audit_reusename(filename); //fill out filename with info from existing entry 141 if (result) 142 return result; 143 144 result = __getname(); //kmem_cache_alloc함수 호출, 코드의 끝에 삽입 145 if (unlikely(!result)) 146 return ERR_PTR(-ENOMEM); 147 148 /* 149 * First, try to embed the struct filename inside the names_cache 150 * allocation 151 */ 152 kname = (char *)result + sizeof(*result); 153 result->name = kname; 154 result->separate = false; 155 max = EMBEDDED_NAME_MAX; 156 157 recopy: 158 len = strncpy_from_user(kname, filename, max); 159 if (unlikely(len < 0)) { 160 err = ERR_PTR(len); 161 goto error; 162 } 163 164 /* 165 * Uh-oh. We have a name that's approaching PATH_MAX. Allocate a 166 * separate struct filename so we can dedicate the entire 167 * names_cache allocation for the pathname, and re-do the copy from 168 * userland. 169 */ 170 if (len == EMBEDDED_NAME_MAX && max == EMBEDDED_NAME_MAX) { 171 kname = (char *)result; 172 173 result = kzalloc(sizeof(*result), GFP_KERNEL); 174 if (!result) { 175 err = ERR_PTR(-ENOMEM); 176 result = (struct filename *)kname; 177 goto error; 178 } 179 result->name = kname; 180 result->separate = true; 181 max = PATH_MAX; 182 goto recopy; 183 } 184 185 /* The empty path is special. */ 186 if (unlikely(!len)) { 187 if (empty) 188 *empty = 1; 189 err = ERR_PTR(-ENOENT); 190 if (!(flags & LOOKUP_EMPTY)) 191 goto error; 192 } 193 194 err = ERR_PTR(-ENAMETOOLONG); 195 if (unlikely(len >= PATH_MAX)) 196 goto error; 197 198 result->uptr = filename; 199 result->aname = NULL; 200 audit_getname(result); 201 return result; 202 203 error: 204 final_putname(result); 205 return err; 206 } 2109 #define __getname() kmem_cache_alloc(names_cachep, GFP_KERNEL) //GFP_KERNEL (__GFP_WAIT | __GFP_IO | __GFP_FS) (=Can wait and reschedule or Can start physical IO? or Can call down to low-level FS?) 3456 /** 3457 * kmem_cache_alloc - Allocate an object 3458 * @cachep: The cache to allocate from. 3459 * @flags: See kmalloc(). 3460 * 3461 * Allocate an object from this cache. The flags are only relevant 3462 * if the cache has no available objects. 3463 */ 3464 void *kmem_cache_alloc(struct kmem_cache *cachep, gfp_t flags) 3465 { 3466 void *ret = slab_alloc(cachep, flags, _RET_IP_); 3467 3468 trace_kmem_cache_alloc(_RET_IP_, ret, 3469 cachep->object_size, cachep->size, flags); 3470 3471 return ret; 3472 } 3473 EXPORT_SYMBOL(kmem_cache_alloc);