Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp256713imm; Wed, 11 Jul 2018 01:44:01 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd2XCu/fL0bRJhc4McbitQ1qFpnY8p6yTJPS2yeNKz0Dcz4qfbHaLr/4REMki13GHY0lQT4 X-Received: by 2002:a17:902:654b:: with SMTP id d11-v6mr27605238pln.8.1531298640962; Wed, 11 Jul 2018 01:44:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531298640; cv=none; d=google.com; s=arc-20160816; b=GQIHL3WXRjC0ClPFPIvxe8ZeribZp/v6DMjaOdxItulATBrnl/JT6cA2e/Y7KKFcfH Q9s+9/GZhsArLjASJCwZ3DI9ly9kpYuqv9e5j0I5GTCmlNVBPj4x+kFQHelmyar0lnoh 9YL1y45CmZqBAllaMy3LuB6RN/AyDGTLnET5uR4jjyZSx/zxrwfKKoRpCui6n0yBosp3 RvrRqz7/j3ro3azGdJv2NiK36KaZcgnU9H805e3Zb3/NiqTst5z5HW1tG11YTuwG1m2o LFldwxcgvrMN2ASy05f52/ogHcR2OegRUpYT+UB2kul4m+KwnRyRlYAZ0PvJ58Lo0+az gtzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:content-transfer-encoding :mime-version:subject:cc:to:references:in-reply-to:from:organization :arc-authentication-results; bh=rpgfJ4sMdX0o/6AphqbmmIp0mj3dJAc8cpU/NQiCtVI=; b=Slm88n/pZ+rmtJcBE9XHKb4zGMD9y/cm+2u1POZCtV+AaWQdYpxKzacMXFMNzptco9 YyGW9vmuZjjIHGT04ko28xf4t6cdP642DZtiTka/dQJ2XPoMHbggUYYcJ3UxPMLjHgYb 5+/ZH/k4lWrjnKRkizYH/lpJ6JHxJ0IKbCh0a1ajiKPn7ZsldgIrVhnttrzqDTPl/CSc PWO+m/VSBWUOaNmhJVQEKFQ/iX4BKTWZ5sPRfJAyYOg5B6BMyte2cndUyeAj87Xnqjg4 DP5YYd+fW49ggOBaXtpOEBHTQj/iaRXgOycuAu/FkQBFdsSaVC5RyP3zOf0LSpsrHGDl NEsg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3-v6si19257635pla.418.2018.07.11.01.43.45; Wed, 11 Jul 2018 01:44:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732501AbeGKIps convert rfc822-to-8bit (ORCPT + 99 others); Wed, 11 Jul 2018 04:45:48 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54120 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726280AbeGKIps (ORCPT ); Wed, 11 Jul 2018 04:45:48 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C27BB40200A7; Wed, 11 Jul 2018 08:42:35 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-120-149.rdu2.redhat.com [10.10.120.149]) by smtp.corp.redhat.com (Postfix) with ESMTP id B7CDB2156891; Wed, 11 Jul 2018 08:42:34 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells In-Reply-To: References: <153126248868.14533.9751473662727327569.stgit@warthog.procyon.org.uk> <153126264966.14533.3388004240803696769.stgit@warthog.procyon.org.uk> <686E805C-81F3-43D0-A096-50C644C57EE3@amacapital.net> To: Linus Torvalds Cc: dhowells@redhat.com, Andy Lutomirski , Al Viro , Linux API , linux-fsdevel , Linux Kernel Mailing List , Jann Horn Subject: Re: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9] MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT Date: Wed, 11 Jul 2018 09:42:34 +0100 Message-ID: <24347.1531298554@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 11 Jul 2018 08:42:35 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 11 Jul 2018 08:42:35 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'dhowells@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Linus Torvalds wrote: > Yeah, Andy is right that we should *not* make "write()" have side effects. Note that write() has side effects all over the place: procfs, sysfs, debugfs, tracefs, ... Though for the most part they're single-shot jobs and not cumulative (I'm not sure this is always true for debugfs - there's a lot of weird stuff in there). > > (b) Keep the current structure but use a new syscall instead of write(). > > > > (c) Keep using write() but literally just buffer the data. Then have a new > > syscall to commit it. In other words, replace “x” with a syscall and call > > all the fs_context_operations helpers in that context instead of from > > write(). > > But yeah, b-or-c sounds fine. I would prefer to avoid the "let's buffer everything" but rather parse the data as we go along. What I currently do is store the parsed data in the context and only actually *apply* it when someone sends the 'x' command. There are two reasons for this: (1) mount()'s error handling is slight: it can only return an error code, but creating and mounting something has so many different and interesting ways of going wrong and I want to be able to give better error reporting. This gets more interesting if it happens inside a container where you can't see dmesg. (2) Parsing the data means you only need to store the result of the parse and can reject anything that's unknown or contradictory. Buffering till the end means you have to buffer *everything* - and, unless you limit your buffer, you risk running out of RAM. Now, I can replace the 'x' command with an ioctl() so that just writing random rubbish to the fd won't cause anything to actually happen. fd = fsopen("ext4"); write(fd, "s /dev/sda1"); write(fd, "o user_xattr"); ioctl(fd, FSOPEN_IOC_CREATE_SB, 0); or I could make a special syscall for it: fscommit(fd, FSCOMMIT_CREATE); or: fscommit(fd, FSCOMMIT_RECONFIGURE); and require that you have CAP_SYS_ADMIN to enact it. David