函数源码

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source File:fs\quota\dquot.c Create Date:2022-07-29 11:08:58
首页 Copyright©Brick

2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
int dquot_load_quota_sb(struct super_block *sb, int type, int format_id,
    unsigned int flags)
{
    struct quota_format_type *fmt = find_quota_format(format_id);
    struct quota_info *dqopt = sb_dqopt(sb);
    int error;
 
    /* Just unsuspend quotas? */
    BUG_ON(flags & DQUOT_SUSPENDED);
    /* s_umount should be held in exclusive mode */
    if (WARN_ON_ONCE(down_read_trylock(&sb->s_umount)))
        up_read(&sb->s_umount);
 
    if (!fmt)
        return -ESRCH;
    if (!sb->s_op->quota_write || !sb->s_op->quota_read ||
        (type == PRJQUOTA && sb->dq_op->get_projid == NULL)) {
        error = -EINVAL;
        goto out_fmt;
    }
    /* Filesystems outside of init_user_ns not yet supported */
    if (sb->s_user_ns != &init_user_ns) {
        error = -EINVAL;
        goto out_fmt;
    }
    /* Usage always has to be set... */
    if (!(flags & DQUOT_USAGE_ENABLED)) {
        error = -EINVAL;
        goto out_fmt;
    }
    if (sb_has_quota_loaded(sb, type)) {
        error = -EBUSY;
        goto out_fmt;
    }
 
    if (!(dqopt->flags & DQUOT_QUOTA_SYS_FILE)) {
        /* As we bypass the pagecache we must now flush all the
         * dirty data and invalidate caches so that kernel sees
         * changes from userspace. It is not enough to just flush
         * the quota file since if blocksize < pagesize, invalidation
         * of the cache could fail because of other unrelated dirty
         * data */
        sync_filesystem(sb);
        invalidate_bdev(sb->s_bdev);
    }
 
    error = -EINVAL;
    if (!fmt->qf_ops->check_quota_file(sb, type))
        goto out_fmt;
 
    dqopt->ops[type] = fmt->qf_ops;
    dqopt->info[type].dqi_format = fmt;
    dqopt->info[type].dqi_fmt_id = format_id;
    INIT_LIST_HEAD(&dqopt->info[type].dqi_dirty_list);
    error = dqopt->ops[type]->read_file_info(sb, type);
    if (error < 0)
        goto out_fmt;
    if (dqopt->flags & DQUOT_QUOTA_SYS_FILE) {
        spin_lock(&dq_data_lock);
        dqopt->info[type].dqi_flags |= DQF_SYS_FILE;
        spin_unlock(&dq_data_lock);
    }
    spin_lock(&dq_state_lock);
    dqopt->flags |= dquot_state_flag(flags, type);
    spin_unlock(&dq_state_lock);
 
    error = add_dquot_ref(sb, type);
    if (error)
        dquot_disable(sb, type, flags);
 
    return error;
out_fmt:
    put_quota_format(fmt);
 
    return error;
}