The original code forgot to check 'inherit', we should
gurantee that all the qgroups in the struct 'inherit' exist.
Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com>
Reviewed-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Josef Bacik <jbacik@fusionio.com>
        struct btrfs_qgroup *srcgroup;
        struct btrfs_qgroup *dstgroup;
        u32 level_size = 0;
+       u64 nums;
 
        mutex_lock(&fs_info->qgroup_ioctl_lock);
        if (!fs_info->quota_enabled)
                goto out;
        }
 
+       if (inherit) {
+               i_qgroups = (u64 *)(inherit + 1);
+               nums = inherit->num_qgroups + 2 * inherit->num_ref_copies +
+                      2 * inherit->num_excl_copies;
+               for (i = 0; i < nums; ++i) {
+                       srcgroup = find_qgroup_rb(fs_info, *i_qgroups);
+                       if (!srcgroup) {
+                               ret = -EINVAL;
+                               goto out;
+                       }
+                       ++i_qgroups;
+               }
+       }
+
        /*
         * create a tracking group for the subvol itself
         */