Author: vlendec
Date: 2004-08-20 10:52:48 +0000 (Fri, 20 Aug 2004)
New Revision: 1953

WebSVN: 
http://websvn.samba.org/websvn/changeset.php?rep=samba&path=/trunk/source&rev=1953&nolog=1

Log:
Merge jerry's "tighten the cache consistency with the ntprinters.tdb entry an
the in memory cache ..." to trunk.

Volker

Modified:
   trunk/source/include/messages.h
   trunk/source/lib/messages.c
   trunk/source/printing/nt_printing.c
   trunk/source/printing/printing.c
   trunk/source/rpc_server/srv_spoolss_nt.c
   trunk/source/smbd/connection.c
   trunk/source/smbd/reply.c
   trunk/source/smbd/server.c


Changeset:
Modified: trunk/source/include/messages.h
===================================================================
--- trunk/source/include/messages.h     2004-08-20 10:22:22 UTC (rev 1952)
+++ trunk/source/include/messages.h     2004-08-20 10:52:48 UTC (rev 1953)
@@ -50,11 +50,13 @@
 
 /* printing messages */
 /* #define MSG_PRINTER_NOTIFY  2001*/ /* Obsolete */
-#define MSG_PRINTER_DRVUPGRADE         2002
-#define MSG_PRINTER_NOTIFY2            2003
-#define MSG_PRINTERDATA_INIT_RESET     2004
-#define MSG_PRINTER_UPDATE             2005
+#define MSG_PRINTER_NOTIFY2            2002
 
+#define MSG_PRINTER_DRVUPGRADE         2101
+#define MSG_PRINTERDATA_INIT_RESET     2102
+#define MSG_PRINTER_UPDATE             2103
+#define MSG_PRINTER_MOD                        2104
+
 /* smbd messages */
 #define MSG_SMB_CONF_UPDATED 3001
 #define MSG_SMB_FORCE_TDIS   3002
@@ -71,6 +73,7 @@
 #define FLAG_MSG_GENERAL       0x0001
 #define FLAG_MSG_SMBD          0x0002
 #define FLAG_MSG_NMBD          0x0004
-#define FLAG_MSG_PRINTING      0x0008
+#define FLAG_MSG_PRINT_NOTIFY  0x0008
+#define FLAG_MSG_PRINT_GENERAL 0x0010
 
 #endif

Modified: trunk/source/lib/messages.c
===================================================================
--- trunk/source/lib/messages.c 2004-08-20 10:22:22 UTC (rev 1952)
+++ trunk/source/lib/messages.c 2004-08-20 10:52:48 UTC (rev 1953)
@@ -576,8 +576,10 @@
                msg_all.msg_flag = FLAG_MSG_GENERAL;
        else if (msg_type > 1000 && msg_type < 2000)
                msg_all.msg_flag = FLAG_MSG_NMBD;
-       else if (msg_type > 2000 && msg_type < 3000)
-               msg_all.msg_flag = FLAG_MSG_PRINTING;
+       else if (msg_type > 2000 && msg_type < 2100)
+               msg_all.msg_flag = FLAG_MSG_PRINT_NOTIFY;
+       else if (msg_type > 2100 && msg_type < 3000)
+               msg_all.msg_flag = FLAG_MSG_PRINT_GENERAL;
        else if (msg_type > 3000 && msg_type < 4000)
                msg_all.msg_flag = FLAG_MSG_SMBD;
        else

Modified: trunk/source/printing/nt_printing.c
===================================================================
--- trunk/source/printing/nt_printing.c 2004-08-20 10:22:22 UTC (rev 1952)
+++ trunk/source/printing/nt_printing.c 2004-08-20 10:52:48 UTC (rev 1953)
@@ -365,7 +365,18 @@
 
        message_register( MSG_PRINTERDATA_INIT_RESET, reset_all_printerdata );
 
+       /*
+        * register callback to handle invalidating the printer cache 
+        * between smbd processes.
+        */
 
+       message_register( MSG_PRINTER_MOD, receive_printer_mod_msg);
+
+       /* of course, none of the message callbacks matter if you don't
+          tell messages.c that you interested in receiving PRINT_GENERAL 
+          msgs.  This is done in claim_connection() */
+
+
        return True;
 }
 
@@ -3458,6 +3469,27 @@
 #endif
 }
 
+/********************************************************************
+ Send a message to all smbds about the printer that just changed
+ ********************************************************************/
+ 
+static BOOL send_printer_mod_msg( char* printername )
+{
+       int len = strlen(printername);
+       
+       if (!len)
+               return False;
+
+       DEBUG(10,("send_printer_mod_msg: Sending message about printer change [%s]\n",
+               printername));
+               
+       /* spam everyone that we just changed this printer */
+       
+       message_send_all( conn_tdb_ctx(), MSG_PRINTER_MOD, printername, len+1, False, 
NULL );
+
+       return True;
+}
+
 /*
  * The function below are the high level ones.
  * only those ones must be called from the spoolss code.
@@ -3481,6 +3513,7 @@
         */
         
        invalidate_printer_hnd_cache( printer.info_2->sharename );
+       send_printer_mod_msg( printer.info_2->sharename );
        
        switch (level) {
                case 2:

Modified: trunk/source/printing/printing.c
===================================================================
--- trunk/source/printing/printing.c    2004-08-20 10:22:22 UTC (rev 1952)
+++ trunk/source/printing/printing.c    2004-08-20 10:52:48 UTC (rev 1953)
@@ -1183,7 +1183,7 @@
                DEBUG(5,("start_background_queue: background LPQ thread started\n"));
 
                claim_connection( NULL, "smbd lpq backend", 0, False, 
-                       FLAG_MSG_GENERAL|FLAG_MSG_SMBD|FLAG_MSG_PRINTING );
+                       FLAG_MSG_GENERAL|FLAG_MSG_SMBD|FLAG_MSG_PRINT_GENERAL);
 
                if (!locking_init(0)) {
                        exit(1);

Modified: trunk/source/rpc_server/srv_spoolss_nt.c
===================================================================
--- trunk/source/rpc_server/srv_spoolss_nt.c    2004-08-20 10:22:22 UTC (rev 1952)
+++ trunk/source/rpc_server/srv_spoolss_nt.c    2004-08-20 10:52:48 UTC (rev 1953)
@@ -180,7 +180,7 @@
                /* Tell the connections db we're no longer interested in
                 * printer notify messages. */
 
-               register_message_flags( False, FLAG_MSG_PRINTING );
+               register_message_flags( False, FLAG_MSG_PRINT_NOTIFY );
        }
 
        smb_connections--;
@@ -1194,12 +1194,6 @@
                notify2_unpack_msg( &notify, &msg_tv, msg_ptr, msg_len );
                msg_ptr += msg_len;
 
-               /* we don't know if the change was from us or not so kill 
-                  any cached printer objects */
-
-               if ( notify.type == PRINTER_NOTIFY_TYPE )
-                       invalidate_printer_hnd_cache( notify.printer );
-               
                /* add to correct list in container */
                
                notify_msg_ctr_addmsg( &messages, &notify );
@@ -1227,6 +1221,22 @@
 }
 
 /********************************************************************
+ callback to MSG_PRINTER_CHANGED.  When a printer is changed by 
+ one smbd, all of processes must clear their printer cache immediately.
+ ********************************************************************/
+
+void receive_printer_mod_msg(int msg_type, pid_t src, void *buf, size_t len)
+{
+       fstring printername;
+       
+       fstrcpy( printername, buf );
+       
+       DEBUG(10,("receive_printer_mod_msg: Printer change [%s]\n", printername ));
+       
+       invalidate_printer_hnd_cache( printername );
+}
+
+/********************************************************************
  Send a message to ourself about new driver being installed
  so we can upgrade the information for each printer bound to this
  driver
@@ -2641,7 +2651,7 @@
                message_register(MSG_PRINTER_NOTIFY2, receive_notify2_message_list);
                /* Tell the connections db we're now interested in printer
                 * notify messages. */
-               register_message_flags( True, FLAG_MSG_PRINTING );
+               register_message_flags( True, FLAG_MSG_PRINT_NOTIFY );
        }
 
        /* 

Modified: trunk/source/smbd/connection.c
===================================================================
--- trunk/source/smbd/connection.c      2004-08-20 10:22:22 UTC (rev 1952)
+++ trunk/source/smbd/connection.c      2004-08-20 10:52:48 UTC (rev 1953)
@@ -222,7 +222,6 @@
        }
 
        pcrec = (struct connections_data *)dbuf.dptr;
-       pcrec->bcast_msg_flags = msg_flags;
        if (doreg)
                pcrec->bcast_msg_flags |= msg_flags;
        else

Modified: trunk/source/smbd/reply.c
===================================================================
--- trunk/source/smbd/reply.c   2004-08-20 10:22:22 UTC (rev 1952)
+++ trunk/source/smbd/reply.c   2004-08-20 10:52:48 UTC (rev 1953)
@@ -242,7 +242,7 @@
                reload_services(True);
                reopen_logs();
 
-               claim_connection(NULL,"",0,True,FLAG_MSG_GENERAL|FLAG_MSG_SMBD);
+               
claim_connection(NULL,"",0,True,FLAG_MSG_GENERAL|FLAG_MSG_SMBD|FLAG_MSG_PRINT_GENERAL);
 
                already_got_session = True;
                break;

Modified: trunk/source/smbd/server.c
===================================================================
--- trunk/source/smbd/server.c  2004-08-20 10:22:22 UTC (rev 1952)
+++ trunk/source/smbd/server.c  2004-08-20 10:52:48 UTC (rev 1953)
@@ -846,6 +846,8 @@
                exit(1);
 
        /* Setup the main smbd so that we can get messages. */
+       /* don't worry about general printing messages here */
+
        claim_connection(NULL,"",0,True,FLAG_MSG_GENERAL|FLAG_MSG_SMBD);
 
        /* only start the background queue daemon if we are 

Reply via email to