public inbox for cygwin-developers@cygwin.com
 help / color / mirror / Atom feed
From: Michael Haubenwallner <michael.haubenwallner@ssi-schaefer.com>
To: cygwin-developers@cygwin.com
Cc: Michael Haubenwallner <michael.haubenwallner@ssi-schaefer.com>
Subject: [PATCH 5/6] forkables: Keep hardlinks disabled via shared mem.
Date: Wed, 07 Dec 2016 11:00:00 -0000	[thread overview]
Message-ID: <1481108310-14825-6-git-send-email-michael.haubenwallner@ssi-schaefer.com> (raw)
In-Reply-To: <1481108310-14825-1-git-send-email-michael.haubenwallner@ssi-schaefer.com>

To avoid the need for each process to check the filesystem to detect
that hardlink creation is impossible or disabled, cache this fact in
shared memory.  Removing cygfork directory while in use does disable
hardlinks creation.  To (re-)enable hardlinks creation, the cygfork
directory has to exist before the first cygwin process does fork.

	* forkable.cc (dll_list::forkable_ntnamesize): Short cut
	forkables needs to impossible when disabled via shared memory.
	(dll_list::update_forkables_needs): When detecting hardlink
	creation as impossible (not on NTFS) while still (we are the
	first one checking) enabled via shared memory, disable the
	shared memory value.
	(dll_list::request_forkables): Disable the shared memory value
	when hardlinks creation became disabled, that is when the
	cygfork directory was removed.
	* include/cygwin/version.h: Bump CYGWIN_VERSION_SHARED_DATA 6.
	* shared_info.h (struct shared_info): Add member
	prefer_forkable_hardlinks.  Update CURR_SHARED_MAGIC.
	* shared.cc (shared_info::initialize): Initialize
	prefer_forkable_hardlinks to 1 (Yes).
---
 winsup/cygwin/forkable.cc              | 13 +++++++++++++
 winsup/cygwin/include/cygwin/version.h |  2 +-
 winsup/cygwin/shared.cc                |  1 +
 winsup/cygwin/shared_info.h            |  3 ++-
 4 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/winsup/cygwin/forkable.cc b/winsup/cygwin/forkable.cc
index c92a44f..e34be55 100644
--- a/winsup/cygwin/forkable.cc
+++ b/winsup/cygwin/forkable.cc
@@ -522,6 +522,11 @@ dll::create_forkable ()
 size_t
 dll_list::forkable_ntnamesize (dll_type type, PCWCHAR fullntname, PCWCHAR modname)
 {
+  /* per process, this is the first forkables-method ever called */
+  if (forkables_needs == forkables_unknown &&
+      !cygwin_shared->prefer_forkable_hardlinks)
+      forkables_needs = forkables_impossible; /* short cut */
+
   if (forkables_needs == forkables_impossible)
     return 0;
 
@@ -667,6 +672,7 @@ dll_list::update_forkables_needs ()
 	{
 	  debug_printf ("impossible, not on NTFS %W", fn.Buffer);
 	  forkables_needs = forkables_impossible;
+	  cygwin_shared->prefer_forkable_hardlinks = 0;
 	}
     }
 
@@ -1056,6 +1062,13 @@ dll_list::request_forkables ()
 
   set_forkables_inheritance (true);
 
+  if (forkables_needs == forkables_disabled)
+    {
+      /* we do not support (re-)enabling on the fly */
+      forkables_needs = forkables_impossible;
+      cygwin_shared->prefer_forkable_hardlinks = 0;
+    }
+
   if (forkables_needs <= forkables_needless)
     return;
 
diff --git a/winsup/cygwin/include/cygwin/version.h b/winsup/cygwin/include/cygwin/version.h
index 6ba602e..b996e26 100644
--- a/winsup/cygwin/include/cygwin/version.h
+++ b/winsup/cygwin/include/cygwin/version.h
@@ -481,7 +481,7 @@ details. */
    regions.  It is incremented when incompatible changes are made to the shared
    memory region *or* to any named shared mutexes, semaphores, etc. */
 
-#define CYGWIN_VERSION_SHARED_DATA 5
+#define CYGWIN_VERSION_SHARED_DATA 6
 
 /* An identifier used in the names used to create shared objects.  The full
    names include the CYGWIN_VERSION_SHARED_DATA version as well as this
diff --git a/winsup/cygwin/shared.cc b/winsup/cygwin/shared.cc
index 4ed4c11..4d754d0 100644
--- a/winsup/cygwin/shared.cc
+++ b/winsup/cygwin/shared.cc
@@ -328,6 +328,7 @@ shared_info::initialize ()
       init_obcaseinsensitive ();	/* Initialize obcaseinsensitive */
       tty.init ();			/* Initialize tty table  */
       mt.initialize ();			/* Initialize shared tape information */
+      prefer_forkable_hardlinks = 1;    /* Yes */
       /* Defer debug output printing the installation root and installation key
 	 up to this point.  Debug output except for system_printf requires
 	 the global shared memory to exist. */
diff --git a/winsup/cygwin/shared_info.h b/winsup/cygwin/shared_info.h
index ce17c15..ad7c8f4 100644
--- a/winsup/cygwin/shared_info.h
+++ b/winsup/cygwin/shared_info.h
@@ -32,7 +32,7 @@ public:
 /* Data accessible to all tasks */
 
 
-#define CURR_SHARED_MAGIC 0x8fe4d9eeU
+#define CURR_SHARED_MAGIC 0xbc5d6a9cU
 
 #define USER_VERSION   1
 
@@ -48,6 +48,7 @@ class shared_info
   LONG last_used_bindresvport;
   DWORD obcaseinsensitive;
   mtinfo mt;
+  char prefer_forkable_hardlinks; /* single byte access always is atomic */
 
   void initialize ();
   void init_obcaseinsensitive ();
-- 
2.7.3

  parent reply	other threads:[~2016-12-07 11:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-07 10:59 RFC: [PATCH 0/6] When fork fails, retry with hardlinks Michael Haubenwallner
2016-12-07 10:59 ` [PATCH 6/6] forkables: Document hardlink creation at forktime Michael Haubenwallner
2016-12-07 11:00 ` Michael Haubenwallner [this message]
2016-12-07 11:00 ` [PATCH 2/6] dll_list: Track main executable and cygwin1.dll Michael Haubenwallner
2016-12-07 11:02 ` [PATCH 4/6] forkables: On fork failure, retry with hardlinks Michael Haubenwallner
2016-12-07 11:02 ` [PATCH 1/6] dll_list: Store dll file name as full NT path Michael Haubenwallner
2016-12-07 11:14 ` [PATCH 3/6] forkables: Create forkable hardlinks, yet unused Michael Haubenwallner
2016-12-08 15:51 ` RFC: [PATCH 0/6] When fork fails, retry with hardlinks Corinna Vinschen
2017-01-09 17:45   ` Michael Haubenwallner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1481108310-14825-6-git-send-email-michael.haubenwallner@ssi-schaefer.com \
    --to=michael.haubenwallner@ssi-schaefer.com \
    --cc=cygwin-developers@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).