From owner-freebsd-geom@FreeBSD.ORG Mon Jul 23 13:42:23 2012 Return-Path: Delivered-To: freebsd-geom@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 40A771065670; Mon, 23 Jul 2012 13:42:23 +0000 (UTC) (envelope-from mavbsd@gmail.com) Received: from mail-wi0-f178.google.com (mail-wi0-f178.google.com [209.85.212.178]) by mx1.freebsd.org (Postfix) with ESMTP id 3C97D8FC14; Mon, 23 Jul 2012 13:42:22 +0000 (UTC) Received: by wibhr14 with SMTP id hr14so2246744wib.13 for ; Mon, 23 Jul 2012 06:42:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:message-id:date:from:user-agent:mime-version:to:cc:subject :content-type:content-transfer-encoding; bh=jpL8eX87fMDnT61oa1GqO3ite0JXyaW/GBtmyEvjjyg=; b=somsjU+1qNxZW7SeEucsI18I6LDI9KCYrrYTgh/VyRBylI6U/hFKRA49SZjmoTng3b Byp23WK7V5BJvRKxUvSc6v98fveoj8n60uE9mXtc5QC9RwkIt7mBb2Y9PYrIdMfWRKqO USDxUD+DEgPIR0Reze/4b0IsOUuaOEH+jnVjNbQWT4/RmeY0AJof6HjOD3ujkWn6pHe0 JxaNUjQOxS9L9AZxZyBjoUWODQbopsaqehQFL1MmyS//HlW3Fs09d6xWMJiNGcgII9l6 UgLYGdXyj0a4jjXjzmjMEbAiPC/D6OBZw1Oop0pDS7OPGX8dGDnsgQQrxJ3xm7MxWpfG dQaQ== Received: by 10.216.238.30 with SMTP id z30mr8251090weq.223.1343050941198; Mon, 23 Jul 2012 06:42:21 -0700 (PDT) Received: from mavbook.mavhome.dp.ua (pc.mavhome.dp.ua. [212.86.226.226]) by mx.google.com with ESMTPS id fu8sm17010637wib.5.2012.07.23.06.42.19 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 23 Jul 2012 06:42:20 -0700 (PDT) Sender: Alexander Motin Message-ID: <500D54B9.1010800@FreeBSD.org> Date: Mon, 23 Jul 2012 16:42:17 +0300 From: Alexander Motin User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:13.0) Gecko/20120628 Thunderbird/13.0.1 MIME-Version: 1.0 To: freebsd-scsi@freebsd.org, freebsd-geom@FreeBSD.org Content-Type: text/plain; charset=KOI8-R; format=flowed Content-Transfer-Encoding: 7bit Cc: Kris Moore Subject: [RFC] CAM/GEOM media change notification X-BeenThere: freebsd-geom@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: GEOM-specific discussions and implementations List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Jul 2012 13:42:23 -0000 Hi. On PC-BSD developers request and sponsored by iXsystems, Inc, I've made patch for present FreeBSD 10-CURRENT implementing media change notification for DA and CD removable media devices, that I would like to be reviewed and tested. It includes three parts: 1) Modifications to CAM to detect media media changes and report them to disk(9) layer. For modern SATA (and potentially UAS) devices it utilizes Asynchronous Notification mechanism to receive events from hardware. Active polling with TEST UNIT READY commands with 3 seconds period is used for incapable hardware. After that both CD and DA drivers work the same way, detecting two conditions: "NOT READY: Medium not present" after medium was detected previously, and "UNIT ATTENTION: Not ready to ready change, medium may have changed". First one reported to disk(9) as media removal, second as media insert/change. To reliably receive second event new AC_UNIT_ATTENTION async added to make UAs broadcasted to all periphs by generic error handling code. 2) Modifications to GEOM core to handle media remove and change events. Media removal handled by spoiling all consumers attached to the provider. Media change event also schedules provider retaste after spoiling to probe new media. New flag G_CF_ORPHAN was added to consumers to reflect that consumer is in process of destruction. It allows retaste to create new geom instance of the same class, while previous one is still dying. 3) Modifications to several major GEOM classes: DEV -- to report media change events to devd; VFS -- to handle spoiling same as orphan to prevent accessing replaced media. PART class already handles spoiling alike to orphan. As result, such events are reported to devd for USB card reader: - on media inserted: !system=DEVFS subsystem=CDEV type=MEDIACHANGE cdev=da3 !system=DEVFS subsystem=CDEV type=CREATE cdev=da3s1 !system=DEVFS subsystem=CDEV type=CREATE cdev=msdosfs/NIKON D7000 - on media removed: !system=DEVFS subsystem=CDEV type=DESTROY cdev=da3s1 !system=DEVFS subsystem=CDEV type=DESTROY cdev=msdosfs/NIKON D7000 Patch can be found here: http://people.freebsd.org/~mav/mediachange8.patch Any comments/objections/propositions? -- Alexander Motin