[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-ha-dev
Subject:    Re: [Linux-ha-dev] exportfs RA patch
From:       Borislav Borisov <borislav.v.borisov () gmail ! com>
Date:       2012-06-06 17:11:09
Message-ID: CAJb0rsWCnn841Jx1LanxprwtaD7fVxG09ZoF4o2J8sTfhCLz_g () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


On Wed, Jun 6, 2012 at 4:35 PM, Lars Ellenberg <lars.ellenberg@linbit.com>wrote:

> On Wed, Jun 06, 2012 at 02:06:19PM +0300, Borislav Borisov wrote:
> > > Ok. So we forgot about exportfs "*:/path",
> > > which is shown as /path <world>.
> > >
> > > I'd like to have it anchored.
> > > oes this still work for you?
> > >
> > > +               sed -e '$! N; s/\n[[:space:]]\+/ /; t;
> > > s/[[:space:]]\+\([^[:space:]]\+\)\(\n\|$\)/ \1\2/g; s/ <world>$/ */g;
> P;D;'
> >
> >
> > To some extent it does... it will catch the ones that end with <world>,
> but
> > the problem is the search and replaces used are appending a newline.
> Also,
> > I initially missed a replace after the first search and replace.
> Eventually
> > I ended up with something close to what you want:
> > sed -e '$! N; s/\n[[:space:]]\+/ /; s/ <world>$/ */g; t;
> > s/[[:space:]]\+\([^[:space:]]\+\)\(\n\|$\)/ \1\2/g; s/ <world>\(\n\|$\)/
> > *\1/g; P;D;'
> >
> > That one, however, is bugging me a lot.
>
> It is not even strictly correct, I think.
>
You need to change the order of the first too substitutions for the "t;"
> to be correct. See below.
>
> It actually was acting correct, but you do have a point, the other way
around makes more sense.


> > So I came up with another solution,
> > which of course isn't anchored either, but is more readable:
> > sed -n '1h; 1!H; ${g; s/[[:space:]]\+\([^[:space:]]\+\)\(\n\|$\)/
> \1\2/g; s/ <world>/ */g; p}'
>
> I don't like that this is first reading all of it,
> then do a replace over all of it.
> It also breaks if you have white space in path names (which is probably
> a very bad practise, in case it is even legal ;-)
>
>
> > I do not consider myself a sed guru, maybe someone who is can figure a
> > better approach.
>
> I think this one is correct, please see if you can break it.
>
> sed -e '$! N;s/\n[[:space:]]\+<world>/ */; s/\n[[:space:]]\+/ /; t;
> s/[[:space:]]\+\([^[:space:]]\+\)\(\n\|$\)/ \1\2/; s/ <world>\(\n\|$\)/
> *\1/; P;D;'
>
>
If the last line matches the first search/replace everything works as
expected, unfortunately if it ends with a line that has the path and client
spec it breaks on the last line, naturally. Which could explain why you
had  s/[[:space:]]\+\([^[:space:]]\+\)\(\n\|$\)/ \1\2/g originally.


> Note that I dropped the /g from the latter substitutions.
>
> FMTYEWTK:
>  $! N; # append next line, unless end of file
>  s/\n[[:space:]]\+<world>/ */;
>        # join continuation lines and replace <world>, if present.
>  s/\n[[:space:]]\+/ /;
>         # join continuation lines. can not succeed if previous line
> succeeded.
>  t; # if one of the previous two "join lines" succeeded,
>    # print and start new cycle.
>
>  # else:
>  # we have one single line record,
>  # and a potentially partial record as second line
>
>  s/[[:space:]]\+\([^[:space:]]\+\)\(\n\|$\)/ \1\2/;
>        # squeeze spaces between path and client spec
>        # If we put a /g on there, it may also squeeze spaces
>        # within the path spec of a trailing partial record.
>

I tried adding /g to both this one and the one below and ran it vs
ridiculously long path and a path with space in the name (which would
prompt a warning saying that action is not supported, but added the
directory to exportfs anyway) and didn't cause any unexpected behavior.
Just to make sure I ran it agains't a directory with several spaces in it.

       # Which is why I left it off now.
>        # Not sure why I put it in there in the first place.
>  s/ <world>\(\n\|$\)/ *\1/;
>        # if the client spec is <world>, substitute by *
>  P;     # print up to the first newline
>  D;     # delete up to the first newline and start new cycle
>
>
> If we can be sure that exportfs output will always be \n terminated,
> we could leave off the \(\n\|$\) ... \... parts.
>
> Would it be easier to the eye if we break it up into single statements?
>
> sed -e '$! N;' \
>    -e 's/\n[[:space:]]\+<world>/ */;' \
>    -e 's/\n[[:space:]]\+/ /;' \
>    -e 't;' \
>    -e 's/[[:space:]]\+\([^[:space:]]\+\)\(\n\|$\)/ \1\2/;' \
>    -e 's/ <world>\(\n\|$\)/ *\1/;' \
>    -e 'P;D;'
>
> I do not think that it makes a huge difference, but sure is easy on the
eyes.


> Again, please, everybody:
> try to break this with any output exportfs may produce.
>
> If only ... I mean, well, it is 2012, right?
> ah well, never mind :-/
>
> --
> : Lars Ellenberg
> : LINBIT | Your Way to High Availability
> : DRBD/HA support and consulting http://www.linbit.com
> _______________________________________________________
> Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
> http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
> Home Page: http://linux-ha.org/
>

[Attachment #5 (text/html)]

<br><br><div class="gmail_quote">On Wed, Jun 6, 2012 at 4:35 PM, Lars Ellenberg <span \
dir="ltr">&lt;<a href="mailto:lars.ellenberg@linbit.com" \
target="_blank">lars.ellenberg@linbit.com</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"> <div class="im">On Wed, Jun 06, 2012 at 02:06:19PM +0300, \
Borislav Borisov wrote:<br> &gt; &gt; Ok. So we forgot about exportfs \
&quot;*:/path&quot;,<br> &gt; &gt; which is shown as /path &lt;world&gt;.<br>
&gt; &gt;<br>
&gt; &gt; I&#39;d like to have it anchored.<br>
&gt; &gt; oes this still work for you?<br>
&gt; &gt;<br>
&gt; &gt; +                      sed -e &#39;$! N; s/\n[[:space:]]\+/ /; t;<br>
&gt; &gt; s/[[:space:]]\+\([^[:space:]]\+\)\(\n\|$\)/ \1\2/g; s/ &lt;world&gt;$/ */g; \
P;D;&#39;<br> &gt;<br>
&gt;<br>
&gt; To some extent it does... it will catch the ones that end with &lt;world&gt;, \
but<br> &gt; the problem is the search and replaces used are appending a newline. \
Also,<br> &gt; I initially missed a replace after the first search and replace. \
Eventually<br> &gt; I ended up with something close to what you want:<br>
&gt; sed -e &#39;$! N; s/\n[[:space:]]\+/ /; s/ &lt;world&gt;$/ */g; t;<br>
&gt; s/[[:space:]]\+\([^[:space:]]\+\)\(\n\|$\)/ \1\2/g; s/ \
&lt;world&gt;\(\n\|$\)/<br> &gt; *\1/g; P;D;&#39;<br>
&gt;<br>
&gt; That one, however, is bugging me a lot.<br>
<br>
</div>It is not even strictly correct, I think.<br></blockquote><blockquote \
class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid \
rgb(204,204,204);padding-left:1ex"> You need to change the order of the first too \
substitutions for the &quot;t;&quot;<br> to be correct. See below.<br>
<div class="im"><br></div></blockquote><div>It actually was acting correct, but you \
do have a point, the other way around makes more sense.<br>  <br></div><blockquote \
class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid \
rgb(204,204,204);padding-left:1ex"> <div class="im">
&gt; So I came up with another solution,<br>
&gt; which of course isn&#39;t anchored either, but is more readable:<br>
&gt; sed -n &#39;1h; 1!H; ${g; s/[[:space:]]\+\([^[:space:]]\+\)\(\n\|$\)/ \1\2/g; s/ \
&lt;world&gt;/ */g; p}&#39;<br> <br>
</div>I don&#39;t like that this is first reading all of it,<br>
then do a replace over all of it.<br>
It also breaks if you have white space in path names (which is probably<br>
a very bad practise, in case it is even legal ;-)<br>
<div><br> <br></div></blockquote><blockquote class="gmail_quote" style="margin:0pt \
0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div \
class="im"> &gt; I do not consider myself a sed guru, maybe someone who is can figure \
a<br> &gt; better approach.<br>
<br>
</div>I think this one is correct, please see if you can break it.<br>
<br>
sed -e &#39;$! N;s/\n[[:space:]]\+&lt;world&gt;/ */; s/\n[[:space:]]\+/ /; t; \
s/[[:space:]]\+\([^[:space:]]\+\)\(\n\|$\)/ \1\2/; s/ &lt;world&gt;\(\n\|$\)/ *\1/; \
P;D;&#39;<br> <br></blockquote><div><br>If the last line matches the first \
search/replace everything works as expected, unfortunately if it ends with a line \
that has the path and client spec it breaks on the last line, naturally. Which could \
explain why you had   s/[[:space:]]\+\([^[:space:]]\+\)\(\n\|$\)/ \1\2/g \
originally.<br>  </div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> Note that I dropped \
the /g from the latter substitutions.<br> <br>
FMTYEWTK:<br>
  $! N; # append next line, unless end of file<br>
  s/\n[[:space:]]\+&lt;world&gt;/ */;<br>
            # join continuation lines and replace &lt;world&gt;, if present.<br>
<div class="im">  s/\n[[:space:]]\+/ /;<br>
</div>            # join continuation lines. can not succeed if previous line \
succeeded.<br>  t; # if one of the previous two &quot;join lines&quot; succeeded,<br>
      # print and start new cycle.<br>
<br>
  # else:<br>
  # we have one single line record,<br>
  # and a potentially partial record as second line<br>
<br>
  s/[[:space:]]\+\([^[:space:]]\+\)\(\n\|$\)/ \1\2/;<br>
            # squeeze spaces between path and client spec<br>
            # If we put a /g on there, it may also squeeze spaces<br>
            # within the path spec of a trailing partial \
record.<br></blockquote><div><br>I tried adding /g to both this one and the one below \
and ran it vs ridiculously long path and a path with space in the name (which would \
prompt a warning saying that action is not supported, but added the directory to \
exportfs anyway) and didn&#39;t cause any unexpected behavior. Just to make sure I \
ran it agains&#39;t a directory with several spaces in it.<br> <br></div><blockquote \
class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid \
rgb(204,204,204);padding-left:1ex">  # Which is why I left it off now.<br>
            # Not sure why I put it in there in the first place.<br>
  s/ &lt;world&gt;\(\n\|$\)/ *\1/;<br>
            # if the client spec is &lt;world&gt;, substitute by *<br>
  P;       # print up to the first newline<br>
  D;       # delete up to the first newline and start new cycle<br>
<br>
<br>
If we can be sure that exportfs output will always be \n terminated,<br>
we could leave off the \(\n\|$\) ... \... parts.<br>
<br>
Would it be easier to the eye if we break it up into single statements?<br>
<br>
sed -e &#39;$! N;&#39; \<br>
      -e &#39;s/\n[[:space:]]\+&lt;world&gt;/ */;&#39; \<br>
      -e &#39;s/\n[[:space:]]\+/ /;&#39; \<br>
      -e &#39;t;&#39; \<br>
      -e &#39;s/[[:space:]]\+\([^[:space:]]\+\)\(\n\|$\)/ \1\2/;&#39; \<br>
      -e &#39;s/ &lt;world&gt;\(\n\|$\)/ *\1/;&#39; \<br>
      -e &#39;P;D;&#39;<br>
<br></blockquote><div>I do not think that it makes a huge difference, but sure is \
easy on the eyes.<br>  <br></div><blockquote class="gmail_quote" style="margin:0pt \
0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

Again, please, everybody:<br>
try to break this with any output exportfs may produce.<br>
<br>
If only ... I mean, well, it is 2012, right?<br>
ah well, never mind :-/<br>
<div class="HOEnZb"><div class="h5"><br>
--<br>
> Lars Ellenberg<br>
> LINBIT | Your Way to High Availability<br>
> DRBD/HA support and consulting <a href="http://www.linbit.com" \
> target="_blank">http://www.linbit.com</a><br>
_______________________________________________________<br>
Linux-HA-Dev: <a href="mailto:Linux-HA-Dev@lists.linux-ha.org">Linux-HA-Dev@lists.linux-ha.org</a><br>
 <a href="http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev" \
target="_blank">http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev</a><br> Home \
Page: <a href="http://linux-ha.org/" target="_blank">http://linux-ha.org/</a><br> \
</div></div></blockquote></div><br>



_______________________________________________________
Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic