Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp990795ybi; Fri, 14 Jun 2019 06:50:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqzqi+q8rJJPG25/8YhNyMy66/eTmcyukt0MYXycz7GJ7PFRnCsA1wUJ5mUL/NUaoWMUjpuM X-Received: by 2002:a62:7a8a:: with SMTP id v132mr76164187pfc.103.1560520249722; Fri, 14 Jun 2019 06:50:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560520249; cv=none; d=google.com; s=arc-20160816; b=cIsoDHD/a73vYdmPDs6KmYUs592fKzRaeYeMR+/3mgr4czzywA/6ohC3os+qLfTxc0 SMCw+Aw5ayhAlRcj/lMlFXXUWHVZBQZdkagXhwWa2Km9RnkNTmwrXctDevWLrLKNM+C+ b+uAX3icKUAOj4SUjwdkYwOd5BhirF/NvqIfotUPy0FNW6fkxYZV0q8IXka3vT6/yE+V CTA9Vj7FcoEi9yUIadQb2KVLKe43WWwg1gCfIHIJ8Oj4ssJaI+tplZ3I48FvCZH7n8D2 XWlf/lBVIuak6974O7XIUBQjXIzN2oCDdzWW6rWtK8hiZI8lMcYQT3N8/m/YM9hJtMXK Styw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=qVDq0D9OO4glvmHjwdsfU4Vr8j6/j6nCy0HmZ0dRLo4=; b=d+Yw8XVpPa69UpydTvGCh+ke1AsSdBwGg0zeBFMuhQf44Q+cxroK1L4bZWGSL9ZqSs Kf/wjctIjjAdWdPem4znJXA6Tj+/bA137YWyMV4iyI3hqDDsJ43uwJPt3fZa4eOknkJx 6EihBgx0EYy+UsrCsAVnms3u439sac44pdAXPm5y9tFh0CRsqsHUFHRmJyutlsVcRR4a 0Cr7e8YoGnyTUDD0qzL73Ejv3Apo1ecoctVQFYsZ73lgBg8ecDYsOk3i/ZI+F2K+gxTC h6CbW9mFBv82n7rX8Sv0SbhBEjB5VTUqCrhFdoXaAOSmII+RAwCIGM/k1bg0a3droNeP ELBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b=jlnoPumk; 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=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u189si1220077pgu.287.2019.06.14.06.50.33; Fri, 14 Jun 2019 06:50:49 -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; dkim=pass header.i=@yandex-team.ru header.s=default header.b=jlnoPumk; 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=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729236AbfFNNto (ORCPT + 99 others); Fri, 14 Jun 2019 09:49:44 -0400 Received: from forwardcorp1p.mail.yandex.net ([77.88.29.217]:54272 "EHLO forwardcorp1p.mail.yandex.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728659AbfFNNtm (ORCPT ); Fri, 14 Jun 2019 09:49:42 -0400 Received: from mxbackcorp2j.mail.yandex.net (mxbackcorp2j.mail.yandex.net [IPv6:2a02:6b8:0:1619::119]) by forwardcorp1p.mail.yandex.net (Yandex) with ESMTP id 6E12E2E0DEB; Fri, 14 Jun 2019 16:49:38 +0300 (MSK) Received: from smtpcorp1o.mail.yandex.net (smtpcorp1o.mail.yandex.net [2a02:6b8:0:1a2d::30]) by mxbackcorp2j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id 39Vphjpq6N-nbaKmusr; Fri, 14 Jun 2019 16:49:38 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1560520178; bh=qVDq0D9OO4glvmHjwdsfU4Vr8j6/j6nCy0HmZ0dRLo4=; h=In-Reply-To:Message-ID:From:Date:References:To:Subject:Cc; b=jlnoPumk7gJZI0ixDYV80/1/L6jVlKxHcakmFwA55RM19Np4dp3x3nHB7tZx65BSN cC6djB3PALQntHVktvwxg3d+FOTzSX/GenBSGQ3CLnGcxGVUP3/WB0UAbB5qu08f6M QXyRbBPhR/uNk9srWi9FuZUWcw7b101Ny6j/WqZY= Authentication-Results: mxbackcorp2j.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Received: from dynamic-red.dhcp.yndx.net (dynamic-red.dhcp.yndx.net [2a02:6b8:0:40c:a1b1:2ca9:8cc0:4c56]) by smtpcorp1o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id uQaJmBDJhz-nbgScMef; Fri, 14 Jun 2019 16:49:37 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) Subject: Re: [PATCH] drivers/ata: print trim features at device initialization To: James Bottomley , "Martin K. Petersen" , Christoph Hellwig Cc: Jens Axboe , linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Monakhov References: <155989287898.1506.14253954112551051148.stgit@buzz> <048ed77f-8faa-fb67-c6bc-10d953f52f89@yandex-team.ru> <1560116241.3324.19.camel@HansenPartnership.com> <1560206933.3698.27.camel@HansenPartnership.com> From: Konstantin Khlebnikov Message-ID: Date: Fri, 14 Jun 2019 16:49:37 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <1560206933.3698.27.camel@HansenPartnership.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-CA Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11.06.2019 1:48, James Bottomley wrote: > On Mon, 2019-06-10 at 10:49 +0300, Konstantin Khlebnikov wrote: >> On 10.06.2019 0:37, James Bottomley wrote: >>> On Sat, 2019-06-08 at 17:13 +0300, Konstantin Khlebnikov wrote: >>>>> On 08.06.2019 11:25, Christoph Hellwig wrote:> On Fri, Jun 07, >>>>> 2019 >>>>> at 10:34:39AM +0300, Konstantin Khlebnikov wrote: >>>>> > >>>>> > Do we really need to spam dmesg with even more ATA >>>>> crap? What >>>>> about >>>>> > a sysfs file that can be read on demand instead? >>>>> > >>>>> >>>>> Makes sense. >>>>> >>>>> Trim state is exposed for ata_device: >>>>> /sys/class/ata_device/devX.Y/trim >>>>> but there is no link from scsi device to ata device so they >>>>> hard to match. >>>>> >>>>> I'll think about it. >>>> >>>> Nope. There is no obvious way to link scsi device with >>>> ata_device. ata_device is built on top of "transport_class" and >>>> "attribute_container". This some extremely over engineered sysfs >>>> framework used only in ata/scsi. I don't want to touch this. >>> >>> You don't need to know any of that. The problem is actually when >>> the ata transport classes were first created, the devices weren't >>> properly parented. What should have happened, like every other >>> transport class, is that the devices should have descended down to >>> the scsi device as the leaf in an integrated fashion. Instead, >>> what we seem to have is three completely separate trees. >>> >>> So if you look at a SAS device, you see from the pci device: >>> >>> host2/port-2:0/end_device-2:0/target2:0:0/2:0:0:0/block/sdb/sdb1 >>> >>> But if you look at a SATA device, you see three separate paths: >>> >>> ata3/host3/target3\:0\:0/3\:0\:0\:0/block/sda/sda1 >>> ata3/link3/dev3.0/ata_device/dev3.0 >>> ata3/ata_port/ata3 >>> >>> Instead of an integrated tree >>> >>> Unfortunately, this whole thing is unfixable now. If I integrate >>> the tree properly, the separate port and link directories will get >>> subsumed and we won't be able to recover them with judicious >>> linking so scripts relying on them will break. The best we can >>> probably do is add additional links with what we have. >>> >>> To follow the way we usually do it, there should be a link from the >>> ata device to the scsi target, but that wouldn't help you find the >>> "trim" files, so it sounds like you want a link from the scsi >>> device to the ata device, which would? >> >> Yes, I'm talking about link from scsi device to leaf ata_device node. >> >> In libata scsi_device has one to one relation with ata_device. >> So making link like /sys/class/block/sda/device/ata_device should be >> possible easy. >> But I haven't found implicit reference from struct ata_device to >> ata_device in sysfs. > > If that's all you want, it is pretty simple modulo the fact we can only > get at the tdev, not the lower transport device, which is what you > want, but at least it's linear from the symlink. > > The attached patch should do this. > > Now I see this for my non-sas device: > > # ls -l /sys/class/scsi_device/3\:0\:0\:0/device/ata_device > lrwxrwxrwx 1 root root 0 Jun 10 13:39 /sys/class/scsi_device/3:0:0:0/device/ata_device -> ../../../link3/dev3.0 I've tried this too. Such link is not very useful, because attribute 'trim' is deeper and suffix path isn't constant: /sys/class/block/sda/device/ata_device/ata_device/dev1.0/trim while I expect something like /sys/class/block/sda/device/ata_device/trim > > James > > --- > > diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c > index 391ac0503dc0..b644336a6d65 100644 > --- a/drivers/ata/libata-scsi.c > +++ b/drivers/ata/libata-scsi.c > @@ -4576,7 +4576,20 @@ void ata_scsi_scan_host(struct ata_port *ap, int sync) > sdev = __scsi_add_device(ap->scsi_host, channel, id, 0, > NULL); > if (!IS_ERR(sdev)) { > + int r; > + > dev->sdev = sdev; > + /* this is a sysfs stupidity: we don't > + * care if the link actually gets > + * created: there's no error handling > + * for failure and we continue on > + * regardless, but we have to discard > + * the return value like this to > + * defeat unused result checking */ > + r = sysfs_create_link(&sdev->sdev_gendev.kobj, > + &dev->tdev.kobj, > + "ata_device"); > + (void)r; > scsi_device_put(sdev); > } else { > dev->sdev = NULL; > @@ -4703,6 +4716,7 @@ static void ata_scsi_remove_dev(struct ata_device *dev) > ata_dev_info(dev, "detaching (SCSI %s)\n", > dev_name(&sdev->sdev_gendev)); > > + sysfs_remove_link(&sdev->sdev_gendev.kobj, "ata_device"); > scsi_remove_device(sdev); > scsi_device_put(sdev); > } >