Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp193049pxb; Wed, 11 Nov 2020 00:55:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJy0SH5AVrdP2tXbpf0V+6SLb0M1UPsJQn7/A845MUW3rbM5+HN1EKHedP3O9fDfuVKW2ZrT X-Received: by 2002:a17:906:e83:: with SMTP id p3mr23825343ejf.243.1605084937036; Wed, 11 Nov 2020 00:55:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605084937; cv=none; d=google.com; s=arc-20160816; b=TmR8r4X7zZsstoTKUuQa5zJba7AdIfwUaM6D0P9FkNgUMAtq8fDki7mDo6LT9qaX7V Trjr332U+pLAY6P5fyl77DEPAi7j3Bo9yPdV0sT+Poi7w1mIqBDylobLzQ4JOQRB1sgl LCQkTHG5HS3J06crHqVpcSR3FX2n0CUyWLQBowhAPWtNzdKy85eVSWl+NB5/XID+p+1X SaO3EmxE4Bdi0gmKdClKJz4w00mgqg14TEWqT1H0viDQkSxszqQAe2MrJ5qswdU7LbIO t10/v32UiSzQOVLsrqqERbNpRO6LmbSy98wbLuuZnMoQzzpYgPj3o8wZy6pkwUJEB81m ZuZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=iTt8eNsbTj2hc7Fsdm5FJVkGnzmgKMJ/Dp/lxggjlCM=; b=rVlsvwWLK3MP/UCtxL9HWiibjCsVk8MQvtnn8GT9Xksom/dfBZ36je+Y4EzBYMHObD 03CZVtVRIfZlAwiEst8Pr3bK6ZHpH+LpSzQDlciELx2fl3C2DoGIstOt+NfJLzfvNVFZ 6JfI5gGiPUaAMJjV8fFJFYbnQnpcm+xl3pZNGCP+gvpQartl2wPcql+yNmAe9vHvwmZH R3fvkRmm51WaAOGf1a+jmAwcwKHVIxSU0BnZEkReg3TzG8enYGcCSgZFpBauY4tPYfts iN1E9/byAJ/VYCOJLQaqedzhdNa+FJeut6ZyjKpk9SVMgdoQxrR5xnMmOZNSo/1fyOJb zexA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VxqvT1DY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w21si957820edx.274.2020.11.11.00.55.13; Wed, 11 Nov 2020 00:55:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VxqvT1DY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726313AbgKKIxN (ORCPT + 99 others); Wed, 11 Nov 2020 03:53:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726005AbgKKIxM (ORCPT ); Wed, 11 Nov 2020 03:53:12 -0500 Received: from mail-ot1-x343.google.com (mail-ot1-x343.google.com [IPv6:2607:f8b0:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A180AC0613D1; Wed, 11 Nov 2020 00:53:12 -0800 (PST) Received: by mail-ot1-x343.google.com with SMTP id f16so1421538otl.11; Wed, 11 Nov 2020 00:53:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=iTt8eNsbTj2hc7Fsdm5FJVkGnzmgKMJ/Dp/lxggjlCM=; b=VxqvT1DYKk7ExwW0O1/Fn95ePohINSTuLkDRIOq/IBsLepZqdOb8Era4egV1DESrLH 9cbmCrntKBTtPiha5EQ6BkhsLW5RNAstB1kauuxMdWgMtYIpqSavkSuqQcBO3ZF/jxt6 vUtSYhW8gx6S1pXHhRYSOmRsEJ72M7fdPgWpzHGb1eQzo6xUdYuh/+tbexorkxCjmi5k I5Tkkse3u+noQUMr2bF48DO+2J8Oi3BXmFACx95eqp5Ph7hmnPBQ7p4/ffPB0R4nk9rs cW7OyGO2Mee7PWzpywRsSSInBTMRkJgbZ24KSdPORrMmvCJz6zWYq/PRJYw5KqDFU5Xr V25A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=iTt8eNsbTj2hc7Fsdm5FJVkGnzmgKMJ/Dp/lxggjlCM=; b=hiZ545X8egQlQZoucArAWOah7ExAl0LF/QB56MkB7Df5zLcM58iZkppu/kAvlBhhOs kEi9dN7v0N662wKJWieN+g+wdSlkeO2ZkgmGOBO6iVQu96vAKgFmDebAW8mIR7L+q+3B tjvxsUznr9nc/05lgfbencpUGxLLV76hGS6H0TnkNNPbSv/amUE7LFZjpXg+BpvtfHHS KHOvWIFjGOA9eNNzJtNGTQzP0AxGVeBVZzEvFWKFTH+p2GGVd3kdLaZJThQUbCYxqo5o EFY14usgYo10bCGXiobG+kLrb0Jha9oKmsyogXswlAIpA6piEluJip+ur0kOhN5Vovta P0mQ== X-Gm-Message-State: AOAM532O40u92d6PGAOrpKCeOm000LC90+DMjXgXYQEk+k+giszZ4ipI TKTStaR8xf4wKwtd27R8ovVB68OL+D4iw/UYYm29hyO3 X-Received: by 2002:a9d:7ac4:: with SMTP id m4mr3607149otn.116.1605084792081; Wed, 11 Nov 2020 00:53:12 -0800 (PST) MIME-Version: 1.0 References: <20201110200411.GU3576660@ZenIV.linux.org.uk> In-Reply-To: <20201110200411.GU3576660@ZenIV.linux.org.uk> From: yulei zhang Date: Wed, 11 Nov 2020 16:53:00 +0800 Message-ID: Subject: Re: [PATCH 01/35] fs: introduce dmemfs module To: Al Viro Cc: Andrew Morton , Naoya Horiguchi , Paolo Bonzini , linux-fsdevel , kvm , LKML , Xiao Guangrong , Wanpeng Li , Haiwei Li , Yulei Zhang , Xiao Guangrong Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 11, 2020 at 4:04 AM Al Viro wrote: > > On Thu, Oct 08, 2020 at 03:53:51PM +0800, yulei.kernel@gmail.com wrote: > > > +static struct inode * > > +dmemfs_get_inode(struct super_block *sb, const struct inode *dir, umode_t mode, > > + dev_t dev); > > WTF is 'dev' for? > > > +static int > > +dmemfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev) > > +{ > > + struct inode *inode = dmemfs_get_inode(dir->i_sb, dir, mode, dev); > > + int error = -ENOSPC; > > + > > + if (inode) { > > + d_instantiate(dentry, inode); > > + dget(dentry); /* Extra count - pin the dentry in core */ > > + error = 0; > > + dir->i_mtime = dir->i_ctime = current_time(inode); > > + } > > + return error; > > +} > > ... same here, seeing that you only call that thing from the next two functions > and you do *not* provide ->mknod() as a method (unsurprisingly - what would > device nodes do there?) > Thanks for pointing this out. we may need support the mknod method, otherwise the dev is redundant and need to be removed. > > +static int dmemfs_create(struct inode *dir, struct dentry *dentry, > > + umode_t mode, bool excl) > > +{ > > + return dmemfs_mknod(dir, dentry, mode | S_IFREG, 0); > > +} > > + > > +static int dmemfs_mkdir(struct inode *dir, struct dentry *dentry, > > + umode_t mode) > > +{ > > + int retval = dmemfs_mknod(dir, dentry, mode | S_IFDIR, 0); > > + > > + if (!retval) > > + inc_nlink(dir); > > + return retval; > > +} > > > +int dmemfs_file_mmap(struct file *file, struct vm_area_struct *vma) > > +{ > > + return 0; > > +} > > + > > +static const struct file_operations dmemfs_file_operations = { > > + .mmap = dmemfs_file_mmap, > > +}; > > Er... Is that a placeholder for later in the series? Because as it is, > it makes no sense whatsoever - "it can be mmapped, but any access to the > mapped area will segfault". > Yes, we seperate the full implementation for dmemfs_file_mmap into patch 05/35, it will assign the interfaces to handle the page fault. > > +struct inode *dmemfs_get_inode(struct super_block *sb, > > + const struct inode *dir, umode_t mode, dev_t dev) > > +{ > > + struct inode *inode = new_inode(sb); > > + > > + if (inode) { > > + inode->i_ino = get_next_ino(); > > + inode_init_owner(inode, dir, mode); > > + inode->i_mapping->a_ops = &empty_aops; > > + mapping_set_gfp_mask(inode->i_mapping, GFP_HIGHUSER); > > + mapping_set_unevictable(inode->i_mapping); > > + inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode); > > + switch (mode & S_IFMT) { > > + default: > > + init_special_inode(inode, mode, dev); > > + break; > > + case S_IFREG: > > + inode->i_op = &dmemfs_file_inode_operations; > > + inode->i_fop = &dmemfs_file_operations; > > + break; > > + case S_IFDIR: > > + inode->i_op = &dmemfs_dir_inode_operations; > > + inode->i_fop = &simple_dir_operations; > > + > > + /* > > + * directory inodes start off with i_nlink == 2 > > + * (for "." entry) > > + */ > > + inc_nlink(inode); > > + break; > > + case S_IFLNK: > > + inode->i_op = &page_symlink_inode_operations; > > + break; > > Where would symlinks come from? Or anything other than regular files and > directories, for that matter... You are right, so far it just supports regular files and directories.