Skip to contentSkip to conversation

Commit numbers for ro database calls

SEMANAGE Ivan Gyurdiev 3 participants 7 messages Dec 23, 2005 – Jan 3, 2006 SELinux security module

lore
Share & tools
lore
#0 lore raw

This should make Joshua happy... return commit numbers on all ro operations. This does not return commit numbers on rw operations, which is consistent with what the modules code does (I think...).

Next we should take advantage of commit numbers to only re-read the cache on ro calls when the commit number has changed.

----
I don't like how dependency on semanage_store.c is creeping into database.c.
(but it was there to begin with - active_lock, and so on...) - might need to reorganize some of this later..

libsemanage/src/database.c +10 -11
diff -Naurp --exclude-from excludes old/libsemanage/src/database.c new/libsemanage/src/database.c
@@ -45,14 +45,18 @@ static int enter_ro(
 	return STATUS_ERR;
 }
 
-static inline void exit_ro(
+static inline int exit_ro(
 	semanage_handle_t* handle,
 	dbase_config_t* dconfig) {
 
+	int commit_num = semanage_get_commit_number(handle);
+
 	if (!handle->is_in_transaction) {
 		semanage_release_active_lock(handle);
 		dconfig->dtable->drop_cache(dconfig->dbase);
 	}
+
+	return commit_num;
 }
 
 static int enter_rw(
@@ -150,8 +154,7 @@ int dbase_query (
 		return STATUS_ERR;
 	}
 
-	exit_ro(handle, dconfig);
-	return STATUS_SUCCESS;
+	return exit_ro(handle, dconfig);
 }
 
 int dbase_exists (
@@ -168,8 +171,7 @@ int dbase_exists (
 		return STATUS_ERR;
 	}
 
-	exit_ro(handle, dconfig);
-	return STATUS_SUCCESS;
+	return exit_ro(handle, dconfig);
 }
 
 int dbase_count (
@@ -185,8 +187,7 @@ int dbase_count (
 		return STATUS_ERR;
 	}
 
-	exit_ro(handle, dconfig);
-	return STATUS_SUCCESS;
+	return exit_ro(handle, dconfig);
 }
 
 int dbase_iterate(
@@ -203,8 +204,7 @@ int dbase_iterate(
 		return STATUS_ERR;
 	}
 
-	exit_ro(handle, dconfig);
-	return STATUS_SUCCESS;
+	return exit_ro(handle, dconfig);
 }
 
 int dbase_list (
@@ -221,6 +221,5 @@ int dbase_list (
 		return STATUS_ERR;
 	}
 
-	exit_ro(handle, dconfig);
-	return STATUS_SUCCESS;
+	return exit_ro(handle, dconfig);
 }
#2 lore raw
In reply to Joshua Brindle
Quoted 4 lines
Quoted 2 lines

Next we should take advantage of commit numbers to only re-read the cache on ro calls when the commit number has changed.

It only matters when you read more than 1 thing at a time. AFAIK this only happens in semanage for selinux users.

I think we're talking about different things - my comment was about library performance - not re-caching unless we have to (particularly in the policydb case, which is slower). You seem to be referring to using commit numbers in the client to prevent races (which, I agree, is another thing that needs to be done).

Quoted 1 line

However, there are queries done outside a transaction and then a transaction started (mostly error handling, eg: Seuser already defined), technically a race but inconsequential since there is error handling in libsemanage. My example (pywrap-test) implementation makes the transaction window as small as possible since it is a discretionary lock but any libsemanage user needs to be careful with this, perhaps something we should document.

Yes....
In general, is there any documentation about libsemanage (API?)
Or should we start writing that, and how? I don't know how to use any doc. software yet (not even writing manpages), so I'd have to learn. Someone complained about lack of documentation of the seusers format earlier.

Quoted 6 lines
Quoted 4 lines

----
I don't like how dependency on semanage_store.c is creeping into database.c.
(but it was there to begin with - active_lock, and so on...) - might need to reorganize some of this later..

This is because database.c is handling locking when it should really only be handled by semanage_store, since locks are a property of the store.

The database only signals when we're entering and exiting. The store is responsible for managing the lock files, and the details of locking. Not sure how else you'd have it done...

Quoted 1 line

The database (file backend) implementation reads files directly out of the store which is probably broken. Not sure if it is even worth fixing though, since there is already support for non-file backends that seems to work.

How is it broken? How should it read the data?

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#4 lore raw
In reply to Joshua Brindle
Quoted 5 lines
Quoted 4 lines

How is it broken? How should it read the data?

It should request the data from semanage_store if it is being stored in the store, just like you'd request the data from an LDAP server, etc. Right now the database is sneaking into the store without going through the store API, which is broken but like I said, probably not worth the time to fix.

I didn't realize there was an API for reading things from the store.
I guess what you're asking me to do is to move code for read/write into the semanage_store, which I could do, but I'm not sure I see the benefit of that - it will just complicate things and make the store dependent on polymorphism, which I'm guessing you wouldn't like.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#1 lore raw
In reply to Ivan Gyurdiev
Quoted 2 lines · Ivan Gyurdiev

This should make Joshua happy... return commit numbers on all ro operations. This does not return commit numbers on rw operations, which is consistent with what the modules code does (I think...).

great. correct, rw operations are 0 for success <0 for error. This should probably be documented (other than in comments)

Quoted 1 line

Next we should take advantage of commit numbers to only re-read the cache on ro calls when the commit number has changed.

It only matters when you read more than 1 thing at a time. AFAIK this only happens in semanage for selinux users. However, there are queries done outside a transaction and then a transaction started (mostly error handling, eg: Seuser already defined), technically a race but inconsequential since there is error handling in libsemanage. My example (pywrap-test) implementation makes the transaction window as small as possible since it is a discretionary lock but any libsemanage user needs to be careful with this, perhaps something we should document.

Quoted 4 lines

----
I don't like how dependency on semanage_store.c is creeping into database.c.
(but it was there to begin with - active_lock, and so on...) - might need to reorganize some of this later..

This is because database.c is handling locking when it should really only be handled by semanage_store, since locks are a property of the store. The database (file backend) implementation reads files directly out of the store which is probably broken. Not sure if it is even worth fixing though, since there is already support for non-file backends that seems to work.

Quoted 2 lines

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#3 lore raw
In reply to Ivan Gyurdiev
Quoted 8 lines · Ivan Gyurdiev
Quoted 5 lines
Quoted 2 lines

Next we should take advantage of commit numbers to only re-read the cache on ro calls when the commit number has changed.

It only matters when you read more than 1 thing at a time. AFAIK this only happens in semanage for selinux users.

I think we're talking about different things - my comment was about library performance - not re-caching unless we have to (particularly in the policydb case, which is slower). You seem to be referring to using commit numbers in the client to prevent races (which, I agree, is another thing that needs to be done).

Right, but if you do exactly 1 query and then exit (semanage login -l) then it's irrelavent for both cases (race and cache optimization), which was my point.

Quoted 8 lines
Quoted 1 line

However, there are queries done outside a transaction and then a transaction started (mostly error handling, eg: Seuser already defined), technically a race but inconsequential since there is error handling in libsemanage. My example (pywrap-test) implementation makes the transaction window as small as possible since it is a discretionary lock but any libsemanage user needs to be careful with this, perhaps something we should document.

Yes....
In general, is there any documentation about libsemanage (API?)
Or should we start writing that, and how? I don't know how to use any doc. software yet (not even writing manpages), so I'd have to learn. Someone complained about lack of documentation of the seusers format earlier.

There is no API doc outside the headers. Man pages are probably prefered but I don't really know how to make them either. Perhaps Steve has a suggestion for this?

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

----
I don't like how dependency on semanage_store.c is creeping into database.c.
(but it was there to begin with - active_lock, and so on...) - might need to reorganize some of this later..

Quoted 8 lines
Quoted 1 line

This is because database.c is handling locking when it should really only be handled by semanage_store, since locks are a property of the store.

The database only signals when we're entering and exiting. The store is responsible for managing the lock files, and the details of locking. Not sure how else you'd have it done...

Quoted 1 line

The database (file backend) implementation reads files directly out of the store which is probably broken. Not sure if it is even worth fixing though, since there is already support for non-file backends that seems to work.

How is it broken? How should it read the data?

It should request the data from semanage_store if it is being stored in the store, just like you'd request the data from an LDAP server, etc. Right now the database is sneaking into the store without going through the store API, which is broken but like I said, probably not worth the time to fix.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#5 lore raw
In reply to Ivan Gyurdiev
Quoted 7 lines · Ivan Gyurdiev
Quoted 5 lines
Quoted 4 lines

How is it broken? How should it read the data?

It should request the data from semanage_store if it is being stored in the store, just like you'd request the data from an LDAP server, etc. Right now the database is sneaking into the store without going through the store API, which is broken but like I said, probably not worth the time to fix.

I didn't realize there was an API for reading things from the store.\

There isn't exactly, but the dependance on semanage_store that you commented on is a symptom of this. You wouldn't put ldap locking in a database, for example, likewise with semanage_store.

Quoted 4 lines

I guess what you're asking me to do is to move code for read/write into the semanage_store, which I could do, but I'm not sure I see the benefit of that - it will just complicate things and make the store dependent on polymorphism, which I'm guessing you wouldn't like.

Right, these are within the same library so it isn't an issue at all (except maybe stylism) and the current stuff work so I'd rather not touch it. One could always view the _file backends as an extension of semanage_store, which makes them unconditionally depenadant on it, which
I'm fine with.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#6 lore raw
In reply to Joshua Brindle
Quoted 9 lines · Joshua Brindle
Quoted 8 lines · Ivan Gyurdiev

Yes....
In general, is there any documentation about libsemanage (API?) Or should we start writing that, and how? I don't know how to use any doc. software yet
(not even writing manpages), so I'd have to learn. Someone complained about lack of
documentation of the seusers format earlier.

Quoted 3 lines

There is no API doc outside the headers. Man pages are probably prefered but I don't really know how to make them either. Perhaps Steve has a suggestion for this?

man pages are preferred (at least as a starting point; supplemental documentation is fine as well, but man pages should always be available). Just copy an existing one from libselinux or libsepol and use it as a template. Prioritize them according to likelihood of use outside of core SELinux code and actual use.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.